mirror of
https://github.com/katanemo/plano.git
synced 2026-04-25 00:36:34 +02:00
add error warning if open ai key is missing
This commit is contained in:
parent
56328bfb16
commit
71613c2789
2 changed files with 5 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -7,3 +7,4 @@ grafana-data
|
|||
prom_data
|
||||
.env
|
||||
qdrant_data
|
||||
demos/weather-forecast/generated/
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@ async def make_completion(messages:List[Message], nb_retries:int=3, delay:int=30
|
|||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {OPENAI_API_KEY}"
|
||||
}
|
||||
|
||||
if OPENAI_API_KEY is None or OPENAI_API_KEY == "":
|
||||
logger.error("No OpenAI API Key found. Please create .env file and set OPENAI_API_KEY env var !")
|
||||
return None
|
||||
try:
|
||||
async with async_timeout.timeout(delay=delay):
|
||||
async with httpx.AsyncClient(headers=header) as aio_client:
|
||||
|
|
@ -61,7 +65,6 @@ async def predict(input, history):
|
|||
Predict the response of the chatbot and complete a running list of chat history.
|
||||
"""
|
||||
history.append({"role": "user", "content": input})
|
||||
print(history)
|
||||
response = await make_completion(history)
|
||||
history.append({"role": "assistant", "content": response})
|
||||
messages = [(history[i]["content"], history[i+1]["content"]) for i in range(0, len(history)-1, 2)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue