Switched to OpenRouter meta-llama/llama-4-scout:free
Browse files- app.py +33 -5
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
from huggingface_hub import InferenceClient # Import Hugging Face InferenceClient
|
|
|
|
| 7 |
|
| 8 |
# (Keep Constants as is)
|
| 9 |
# --- Constants ---
|
|
@@ -18,7 +19,8 @@ class BasicAgent:
|
|
| 18 |
print("BasicAgent initialized.")
|
| 19 |
|
| 20 |
print("Loading huggingface default model...")
|
| 21 |
-
self.client = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.3", token=os.getenv("HF_TOKEN"))
|
|
|
|
| 22 |
|
| 23 |
def __call__(self, question: str) -> str:
|
| 24 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
@@ -26,9 +28,35 @@ class BasicAgent:
|
|
| 26 |
try:
|
| 27 |
# Generate response
|
| 28 |
print("Using Inference API for generation...")
|
| 29 |
-
prompt = f"""<s>[INST] Answer the following question directly without any explanations, introductions, or conclusions. Just provide the answer itself: {question} [/INST]</s>"""
|
| 30 |
-
response = self.client.text_generation(prompt, max_new_tokens=512, do_sample=True, temperature=0.1)
|
| 31 |
-
answer = response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
print(f"Agent generated response (first 50 chars): {answer[:50]}...")
|
| 33 |
return answer
|
| 34 |
except Exception as e:
|
|
@@ -163,7 +191,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
| 163 |
|
| 164 |
# --- Build Gradio Interface using Blocks ---
|
| 165 |
with gr.Blocks() as demo:
|
| 166 |
-
gr.Markdown("# Basic Agent Evaluation Runner #
|
| 167 |
gr.Markdown(
|
| 168 |
"""
|
| 169 |
**Instructions:**
|
|
|
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
from huggingface_hub import InferenceClient # Import Hugging Face InferenceClient
|
| 7 |
+
from openai import OpenAI
|
| 8 |
|
| 9 |
# (Keep Constants as is)
|
| 10 |
# --- Constants ---
|
|
|
|
| 19 |
print("BasicAgent initialized.")
|
| 20 |
|
| 21 |
print("Loading huggingface default model...")
|
| 22 |
+
# self.client = InferenceClient(model="mistralai/Mistral-7B-Instruct-v0.3", token=os.getenv("HF_TOKEN"))
|
| 23 |
+
self.client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.getenv("OR_TOKEN"))
|
| 24 |
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
|
|
|
| 28 |
try:
|
| 29 |
# Generate response
|
| 30 |
print("Using Inference API for generation...")
|
| 31 |
+
# prompt = f"""<s>[INST] Answer the following question directly without any explanations, introductions, or conclusions. Just provide the answer itself: {question} [/INST]</s>"""
|
| 32 |
+
# response = self.client.text_generation(prompt, max_new_tokens=512, do_sample=True, temperature=0.1)
|
| 33 |
+
# answer = response
|
| 34 |
+
completion = self.client.chat.completions.create(
|
| 35 |
+
extra_headers={
|
| 36 |
+
"HTTP-Referer": "<YOUR_SITE_URL>", # Optional. Site URL for rankings on openrouter.ai.
|
| 37 |
+
"X-Title": "<YOUR_SITE_NAME>", # Optional. Site title for rankings on openrouter.ai.
|
| 38 |
+
},
|
| 39 |
+
extra_body={},
|
| 40 |
+
model="meta-llama/llama-4-scout:free",
|
| 41 |
+
messages=[
|
| 42 |
+
{
|
| 43 |
+
"role": "user",
|
| 44 |
+
"content": [
|
| 45 |
+
{
|
| 46 |
+
"type": "text",
|
| 47 |
+
"text": question
|
| 48 |
+
},
|
| 49 |
+
# {
|
| 50 |
+
# "type": "image_url",
|
| 51 |
+
# "image_url": {
|
| 52 |
+
# "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
|
| 53 |
+
# }
|
| 54 |
+
# }
|
| 55 |
+
]
|
| 56 |
+
}
|
| 57 |
+
]
|
| 58 |
+
)
|
| 59 |
+
answer = completion.choices[0].message.content
|
| 60 |
print(f"Agent generated response (first 50 chars): {answer[:50]}...")
|
| 61 |
return answer
|
| 62 |
except Exception as e:
|
|
|
|
| 191 |
|
| 192 |
# --- Build Gradio Interface using Blocks ---
|
| 193 |
with gr.Blocks() as demo:
|
| 194 |
+
gr.Markdown("# Basic Agent Evaluation Runner #16")
|
| 195 |
gr.Markdown(
|
| 196 |
"""
|
| 197 |
**Instructions:**
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
-
huggingface_hub
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
requests
|
| 3 |
+
huggingface_hub
|
| 4 |
+
openai
|