willn9 commited on
Commit
6b7722e
·
verified ·
1 Parent(s): ea76f49

Migrate to Open Ai

Browse files
Files changed (1) hide show
  1. app_openai.py +41 -0
app_openai.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from openai import OpenAI
4
+
5
+ # Initialize the OpenAI client
6
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
7
+
8
+ # Define the response function
9
+ def respond(
10
+ message,
11
+ history: list[tuple[str, str]],
12
+ system_message,
13
+ role,
14
+ education,
15
+ passion,
16
+ fit,
17
+ anecdotes,
18
+ max_tokens,
19
+ temperature,
20
+ top_p,
21
+ ):
22
+ # Construct the enhanced system prompt
23
+ enhanced_system_message = (
24
+ f"{system_message}\n\n"
25
+ f"Role, Industry, Employer and Summary of Job Ad: {role}\n"
26
+ f"Summary of your Education and Work Experience: {education}\n"
27
+ f"Why are you passionate about this job: {passion}\n"
28
+ f"Why do you feel you are a good fit for this job: {fit}\n"
29
+ f"Anecdotes: {anecdotes}\n"
30
+ )
31
+
32
+ # Construct message history
33
+ messages = [{"role": "system", "content": enhanced_system_message}]
34
+ for user_msg, assistant_msg in history:
35
+ if user_msg:
36
+ messages.append({"role": "user", "content": user_msg})
37
+ if assistant_msg:
38
+ messages.append({"role": "assistant", "content": assistant_msg})
39
+ messages.append({"role": "user", "content": message})
40
+
41
+ # Generate and stream response