Skip to content

Commit 89fef54

Browse files
authored
Merge pull request #6 from codejoey/make-open-ai-file
Make open ai utils file
2 parents 1f96955 + dca2083 commit 89fef54

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

openai_utils.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from openai import OpenAI
2+
import key_param
3+
import os
4+
os.environ['OPENAI_API_KEY'] = key_param.openai_api_key
5+
6+
client = OpenAI()
7+
8+
def generate_embedding(text_chunk):
9+
response = client.embeddings.create(input=text_chunk, model="text-embedding-ada-002")
10+
print(response) # Temporarily add this to inspect the structure
11+
# Adjust the attribute access based on the structure you observe
12+
embedding_vector = response.data[0].embedding
13+
return embedding_vector
14+
15+
16+
def generate_summary(text_chunk):
17+
system = [{"role": "system", "content": "You are Summary AI."}]
18+
user = [{"role": "user", "content": f"Summarize this briefly:\n\n{text_chunk}"}]
19+
chat_history = [] # past user and assistant turns, for AI memory
20+
21+
chat_completion = client.chat.completions.create(
22+
messages = system + chat_history + user,
23+
model="gpt-3.5-turbo",
24+
max_tokens=500, top_p=0.9,
25+
)
26+
return(chat_completion.choices[0].message.content)
27+

0 commit comments

Comments
 (0)