alexkueck commited on
Commit
6b513aa
1 Parent(s): 0d3e6b9

Update appOpenAI.py

Browse files
Files changed (1) hide show
  1. appOpenAI.py +25 -1
appOpenAI.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  def predict(message, history):
2
  history_openai_format = []
3
  for human, assistant in history:
@@ -18,4 +20,26 @@ def predict(message, history):
18
  partial_message = partial_message + chunk['choices'][0]['delta']['content']
19
  yield partial_message
20
 
21
- gr.ChatInterface(predict).queue().launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ####################################################
2
+ #Mit Streaming
3
  def predict(message, history):
4
  history_openai_format = []
5
  for human, assistant in history:
 
20
  partial_message = partial_message + chunk['choices'][0]['delta']['content']
21
  yield partial_message
22
 
23
+ gr.ChatInterface(predict).queue().launch()
24
+
25
+ ##########################################################
26
+ #OpenAI Chatinterface
27
+ from langchain.chat_models import ChatOpenAI
28
+ from langchain.schema import AIMessage, HumanMessage
29
+ import openai
30
+ import gradio as gr
31
+
32
+ os.environ["OPENAI_API_KEY"] = "sk-..." # Replace with your key
33
+
34
+ llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613')
35
+
36
+ def predict(message, history):
37
+ history_langchain_format = []
38
+ for human, ai in history:
39
+ history_langchain_format.append(HumanMessage(content=human))
40
+ history_langchain_format.append(AIMessage(content=ai))
41
+ history_langchain_format.append(HumanMessage(content=message))
42
+ gpt_response = llm(history_langchain_format)
43
+ return gpt_response.content
44
+
45
+ gr.ChatInterface(predict).launch()