Update FreeModelUrl.txt
Browse files- FreeModelUrl.txt +54 -0
FreeModelUrl.txt
CHANGED
|
@@ -1 +1,55 @@
|
|
| 1 |
model=HfApiModel('https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
model=HfApiModel('https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'),
|
| 2 |
+
|
| 3 |
+
Alternatively - how to use Ollama local setup
|
| 4 |
+
|
| 5 |
+
I just want to share my solution if this could be useful.
|
| 6 |
+
|
| 7 |
+
1) I ran locally qwen2.5 model. how?
|
| 8 |
+
2) Download ollama from https://ollama.com/download
|
| 9 |
+
3) In terminal, once Ollama is installed run command: ollama pull qwen2.5:7b (some useful info: https://ollama.com/library/qwen2.5)
|
| 10 |
+
4) pip install smolagents, ollama
|
| 11 |
+
5) see script attached. The OllamaModel class was copied from other conversation in our community
|
| 12 |
+
|
| 13 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, Tool, tool, VisitWebpageTool
|
| 14 |
+
import ollama
|
| 15 |
+
|
| 16 |
+
@tool
|
| 17 |
+
def suggest_menu(occasion: str) -> str:
|
| 18 |
+
"""
|
| 19 |
+
Suggests a menu based on the occasion.
|
| 20 |
+
Args:
|
| 21 |
+
occasion: The type of occasion for the party.
|
| 22 |
+
"""
|
| 23 |
+
if occasion == "casual":
|
| 24 |
+
return "Pizza, snacks, and drinks."
|
| 25 |
+
elif occasion == "formal":
|
| 26 |
+
return "3-course dinner with wine and dessert."
|
| 27 |
+
elif occasion == "superhero":
|
| 28 |
+
return "Buffet with high-energy and healthy food."
|
| 29 |
+
else:
|
| 30 |
+
return "Custom menu for the butler."
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class OllamaModel:
|
| 34 |
+
def __init__(self, model_name):
|
| 35 |
+
self.model_name = model_name
|
| 36 |
+
|
| 37 |
+
def __call__(self, prompt, stop_sequences=["Task"]) -> str:
|
| 38 |
+
# Convert the list of prompts to a single string
|
| 39 |
+
prompt_text = ""
|
| 40 |
+
for item in prompt:
|
| 41 |
+
if item['role'] == 'system':
|
| 42 |
+
for content in item['content']:
|
| 43 |
+
if content['type'] == 'text':
|
| 44 |
+
prompt_text += content['text']
|
| 45 |
+
elif item['role'] == 'user':
|
| 46 |
+
for content in item['content']:
|
| 47 |
+
if content['type'] == 'text':
|
| 48 |
+
prompt_text += content['text']
|
| 49 |
+
# Use Ollama's generate or chat API to handle prompts
|
| 50 |
+
response = ollama.chat(model=self.model_name, messages=[{"role": "user", "content": prompt_text}], stream=False)
|
| 51 |
+
return response.message
|
| 52 |
+
|
| 53 |
+
# Initialize the agent with OllamaModel
|
| 54 |
+
ollama_model = OllamaModel(model_name="qwen2.5")
|
| 55 |
+
|