File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments