Skip to content

Commit

Permalink
Merge pull request #6 from codejoey/make-open-ai-file
Browse files Browse the repository at this point in the history
Make open ai utils file
  • Loading branch information
gitbisect authored Feb 23, 2024
2 parents 1f96955 + dca2083 commit 89fef54
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions openai_utils.py
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)

0 comments on commit 89fef54

Please sign in to comment.