我有基本的 OPEN AI 帐户,我正在开发一个 POC,其目标是从 JIRA 获取数据,然后使用 OPEN AI 进行分析。对分析什么和分析多少没有限制,我可以让它尽可能少,我只想让它工作一次。
以下是我的javascript脚本,用于从用户获取数据
document.addEventListener("DOMContentLoaded", function () {
const form = document.getElementById("jqlForm");
form.addEventListener("submit", function (event) {
event.preventDefault();
const project = document.getElementById("project").value.trim();
const sprint = document.getElementById("sprint").value.trim();
const story = document.getElementById("story").value.trim();
let jql = `project = ${project} AND sprint = ${sprint}`;
if (story) {
jql += ` AND issuekey ~ "${story}"`;
}
const jqlInput = document.createElement("input");
jqlInput.type = "hidden";
jqlInput.name = "jql";
jqlInput.value = jql;
form.appendChild(jqlInput);
form.submit();
});
});
对于我的网络应用程序,我使用的是 Flask,因此 app.py 就像
from flask import Flask, render_template, request
import openai
from jira import JIRA
app = Flask(__name__)
JIRA_ACCESS_TOKEN = "myToken"
JIRA_URL = "https://JIRAURL.atlassian.net/"
OPENAI_TOKEN = "openAIToken"
openai.api_key = OPENAI_TOKEN
@app.route("/")
def index():
return render_template("index.html")
def generate_summary(prompt, model="gpt-3.5-turbo"):
try:
response = openai.ChatCompletion.create(
model=model,
messages=[{"role": "user", "content": prompt}],
max_tokens=150, # Adjust based on your needs
temperature=0.5, # Adjust for creativity
top_p=0.9 # Adjust for diversity
)
return response.choices[0].message["content"].strip()
except Exception as e:
print(f"An error occurred: {e}")
return "Error: Unable to process request."
def get_sprint_context(sprint_summary, sprint):
prompt = f"You are going to read a list of summary of defect tickets. I want you to analyze the list of defects encountered during {sprint} and provide a summary focusing on which area of the application has more problems, using project management language. Do not use bullet points and in short summary highlight the facts about problematic areas of my application."
return generate_summary(f"List of defects: {sprint_summary}\n\n{prompt}")
def call_gpt(jira_ticket):
prompt = f"This is the response from JIRA getIssue platform API. I want you to give a detailed analysis of this JIRA ticket: {jira_ticket}"
return generate_summary(prompt)
@app.route("/sprint", methods=['POST'])
def sprint_context():
if request.method == 'POST':
jql = request.form.get("jql") # Receive the JQL string from the frontend
sprint = request.form.get("sprint")
if jql and sprint:
jira_client = JIRA(JIRA_URL, basic_auth=("[email protected]", JIRA_ACCESS_TOKEN))
issues = jira_client.search_issues(jql)
summary = [issue.fields.summary for issue in issues]
sprint_context = get_sprint_context(summary, sprint)
return render_template('summary.html', my_string=sprint_context)
else:
return "Missing JQL or Sprint data", 400
return "Invalid Request", 400
if __name__ == "__main__":
app.run(debug=True)
我面临的问题是,当我在 OPEN AI web 上创建新的 API 密钥并第一次添加并运行它时,它直接说我已经超出了限制范围,这不起作用,因此,但是,我需要解决并使其发挥作用。这是 POC 的负担,我可以做出任何有效的改变,用最少的数据、最少的分析,但同样的集成。请建议可以做什么??
这个错误出现很多次。这不是你的问题。
我也面临同样的问题。我有积分,但 api 密钥仍然显示“OpenAI API 错误 429:“您超出了当前配额,请检查您的计划和账单详细信息”
为了避免这种情况,您可以通过将密钥插入此卷曲来测试这一点
curl --location 'https://api.openai.com/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR-API-KEY}' \
--header 'Cookie: _cf_bm=JK13hz8bDzqGHlF4QHt0oeZZNQkxJmNfR2b6YHtLdDQ-1727799752-1.0.1.1-mbQSEsSobRx6J_PTAo2qi7TKzTp6T6lLr50eb7nFa9XoKeTrYp.mNVFUllRck.lnxxZoIrLX85NXSSyGXpkWrw; cfuvid=mY9O7cSq2gAT.MUJP4cx.eRL.vKnYmcHS74oGHFgUh0-1727798356054-0.0.1.1-604800000' \
--data '{
"model": "gpt-4",
"messages": [
{ "role": "system", "content": "You are a creative and vivid storyteller." },
{ "role": "user", "content": "Create an engaging and informative video script that explains the impact of Artificial Intelligence (AI) on healthcare" }
],
"max_tokens": 300
}'
在任何项目中使用之前,请尝试重新生成,如果不起作用,请与 open ai 联系。您可以根据规格更改模态。