-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from codejoey/make-open-ai-file
Make open ai utils file
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from openai import OpenAI | ||
import key_param | ||
import os | ||
os.environ['OPENAI_API_KEY'] = key_param.openai_api_key | ||
|
||
client = OpenAI() | ||
|
||
def generate_embedding(text_chunk): | ||
response = client.embeddings.create(input=text_chunk, model="text-embedding-ada-002") | ||
print(response) # Temporarily add this to inspect the structure | ||
# Adjust the attribute access based on the structure you observe | ||
embedding_vector = response.data[0].embedding | ||
return embedding_vector | ||
|
||
|
||
def generate_summary(text_chunk): | ||
system = [{"role": "system", "content": "You are Summary AI."}] | ||
user = [{"role": "user", "content": f"Summarize this briefly:\n\n{text_chunk}"}] | ||
chat_history = [] # past user and assistant turns, for AI memory | ||
|
||
chat_completion = client.chat.completions.create( | ||
messages = system + chat_history + user, | ||
model="gpt-3.5-turbo", | ||
max_tokens=500, top_p=0.9, | ||
) | ||
return(chat_completion.choices[0].message.content) | ||
|