Spaces:
Build error
Build error
Commit
·
9adba36
1
Parent(s):
b9f5d20
Add application file
Browse files
app.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
| 1 |
-
import
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
return "Hello " + name + "!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.chat_models import ChatOpenAI
|
| 2 |
+
from langchain.schema import AIMessage, HumanMessage
|
| 3 |
+
import openai
|
| 4 |
+
import gradio as gr
|
| 5 |
|
| 6 |
+
os.environ["OPENAI_API_KEY"] = "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" # Replace with your key
|
|
|
|
| 7 |
|
| 8 |
+
llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613')
|
| 9 |
+
|
| 10 |
+
def predict(message, history):
|
| 11 |
+
history_langchain_format = []
|
| 12 |
+
for human, ai in history:
|
| 13 |
+
history_langchain_format.append(HumanMessage(content=human))
|
| 14 |
+
history_langchain_format.append(AIMessage(content=ai))
|
| 15 |
+
history_langchain_format.append(HumanMessage(content=message))
|
| 16 |
+
gpt_response = llm(history_langchain_format)
|
| 17 |
+
return gpt_response.content
|
| 18 |
+
|
| 19 |
+
gr.ChatInterface(predict).launch()
|