Spaces:
Running
Running
Update app.py
Browse files7 unmodified lines89101112131415161754 unmodified lines72737475767747 unmodified lines1251261271281291307 unmodified linesfrom config import API_KEY, MODEL, SYSTEM_PROMPT, ENDPOINT, EXAMPLES, DEFAULT_LOCALE, DEFAULT_THEMEfrom huggingface_hub import InferenceClient# Initialize both clientshf_client = InferenceClient(model=MODEL, token=API_KEY)openai_client = OpenAI(api_key=API_KEY, base_url=ENDPOINT + MODEL)react_imports = {"lucide-react": "https://esm.sh/lucide-react@0.525.0","recharts": "https://esm.sh/recharts@3.1.0",54 unmodified linesmessages.append({'role': 'user', 'content': input_value})try:# Try using HuggingFace InferenceClient firstformatted_messages = [{"role": msg["role"], "content": msg["content"]} for msg in messages]response = ""47 unmodified linesexcept Exception as e:# Fallback to OpenAI client if HuggingFace client failstry:generator = openai_client.chat.completions.create(model=MODEL,messages=messages,stream=True)7 unmodified lines891011121354 unmodified lines68697071727374757647 unmodified lines1241251261271281291301311327 unmodified linesfrom config import API_KEY, MODEL, SYSTEM_PROMPT, ENDPOINT, EXAMPLES, DEFAULT_LOCALE, DEFAULT_THEMEfrom huggingface_hub import InferenceClientreact_imports = {"lucide-react": "https://esm.sh/lucide-react@0.525.0","recharts": "https://esm.sh/recharts@3.1.0",54 unmodified linesmessages.append({'role': 'user', 'content': input_value})try:# Initialize HuggingFace InferenceClienthf_client = InferenceClient(model=MODEL, token=API_KEY)# Try using HuggingFace InferenceClient firstformatted_messages = [{"role": msg["role"], "content": msg["content"]} for msg in messages]response = ""47 unmodified linesexcept Exception as e:# Fallback to OpenAI client if HuggingFace client failstry:# Initialize OpenAI clientopenai_client = OpenAI(api_key=API_KEY, base_url=ENDPOINT + MODEL)generator = openai_client.chat.completions.create(model=MODEL,messages=messages,stream=True)
app.py+6-4