Spaces:
Runtime error
Runtime error
File size: 1,757 Bytes
70d23d8 dbd71cd 850b06a 7759aac 850b06a 35941ce 850b06a 7759aac dbd71cd cafb625 dbd71cd 245f86a 70d23d8 245f86a cafb625 245f86a cafb625 245f86a 70d23d8 245f86a cafb625 245f86a cafb625 245f86a 353feec def6407 245f86a 2b749f0 f26eb10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | import json
import os
import gradio as gr
os.environ['OPENAI_API_KEY']=os.getenv('OpenAI_KEY')
os.environ["LANGCHAIN_API_KEY"]=os.getenv('LANGCHAIN_API_KEY')
os.environ["LANGCHAIN_TRACING_V2"]="true"
os.environ["LANGCHAIN_ENDPOINT"]="https://api.smith.langchain.com"
os.environ["LANGCHAIN_PROJECT"]=os.getenv('LANGCHAIN_PROJECT')
import openai
from langsmith.wrappers import wrap_openai
from langsmith import traceable
# Auto-trace LLM calls in-context
client = wrap_openai(openai.Client())
FakeNewsAggregator = client.beta.assistants.retrieve(os.getenv('OPENAI_ASSISTANT_ID'))
thread= client.beta.threads.create()
@traceable # Auto-trace this function
def FakeNewsAggregatorRequest(text):
global FakeNewsAggregator
global thread
message = client.beta.threads.messages.create(
thread_id=thread.id,
role="user",
content=text
)
run = client.beta.threads.runs.create_and_poll(
thread_id=thread.id,
assistant_id=FakeNewsAggregator.id
)
if run.status == 'completed':
messages = client.beta.threads.messages.list(
thread_id=thread.id
)
gpt_response=messages.data[0].content[0].text.value
return gpt_response
else:
return run.status
gr.Interface(fn=FakeNewsAggregatorRequest,
inputs=["text"],
outputs=["text"],
flagging_mode='never',
title="Did Elon Musk actually say that?",
description="I am virtual assistant to help you verify Elon Musk's opinions ",
theme="soft",
examples=['Elon Musk and free speech','Elon musk on climate change', 'Elon Musk on disinformation']
).launch(share=False)
|