Spaces:
Sleeping
Sleeping
Commit
·
785b85c
1
Parent(s):
ff10eab
Minor Fix
Browse files
app.py
CHANGED
@@ -51,7 +51,7 @@ def read_root():
|
|
51 |
async def list_models():
|
52 |
"""List all available models in Ollama."""
|
53 |
try:
|
54 |
-
response =
|
55 |
except Exception as e:
|
56 |
return {"error": str(e)}
|
57 |
|
@@ -60,7 +60,7 @@ async def list_models():
|
|
60 |
@app.post("/pull_model")
|
61 |
async def pull_model(model_name: str):
|
62 |
"""Pull a model from Ollama's repository."""
|
63 |
-
response =
|
64 |
# print(response)
|
65 |
|
66 |
return response.json()
|
@@ -70,7 +70,7 @@ async def pull_model(model_name: str):
|
|
70 |
async def generate_text(model: str, prompt: str, system: str = "You are a helpful AI assistant.", stream: bool = False):
|
71 |
"""Generate text from a given prompt using a specific model."""
|
72 |
try:
|
73 |
-
response =
|
74 |
f"{OLLAMA_URL}/api/generate",
|
75 |
json={"model": model, "prompt": prompt, "system": system, "stream": stream}
|
76 |
)
|
@@ -84,7 +84,7 @@ async def generate_text(model: str, prompt: str, system: str = "You are a helpfu
|
|
84 |
async def get_embedding(model: str, text: str):
|
85 |
"""Generate embeddings for the given text using a model."""
|
86 |
try:
|
87 |
-
response =
|
88 |
f"{OLLAMA_URL}/api/embeddings",
|
89 |
json={"model": model, "prompt": text}
|
90 |
)
|
@@ -98,7 +98,7 @@ async def get_embedding(model: str, text: str):
|
|
98 |
async def chat(model: str, message: str, system: str = "You are a helpful chatbot."):
|
99 |
"""Chat with the model while maintaining context."""
|
100 |
try:
|
101 |
-
response =
|
102 |
f"{OLLAMA_URL}/api/chat",
|
103 |
json={"model": model, "messages": [{"role": "system", "content": system}, {"role": "user", "content": message}]}
|
104 |
)
|
|
|
51 |
async def list_models():
|
52 |
"""List all available models in Ollama."""
|
53 |
try:
|
54 |
+
response = requests.get(f"{OLLAMA_URL}/api/tags")
|
55 |
except Exception as e:
|
56 |
return {"error": str(e)}
|
57 |
|
|
|
60 |
@app.post("/pull_model")
|
61 |
async def pull_model(model_name: str):
|
62 |
"""Pull a model from Ollama's repository."""
|
63 |
+
response = requests.post(f"{OLLAMA_URL}/api/pull", json={"name": model_name})
|
64 |
# print(response)
|
65 |
|
66 |
return response.json()
|
|
|
70 |
async def generate_text(model: str, prompt: str, system: str = "You are a helpful AI assistant.", stream: bool = False):
|
71 |
"""Generate text from a given prompt using a specific model."""
|
72 |
try:
|
73 |
+
response = requests.post(
|
74 |
f"{OLLAMA_URL}/api/generate",
|
75 |
json={"model": model, "prompt": prompt, "system": system, "stream": stream}
|
76 |
)
|
|
|
84 |
async def get_embedding(model: str, text: str):
|
85 |
"""Generate embeddings for the given text using a model."""
|
86 |
try:
|
87 |
+
response = requests.post(
|
88 |
f"{OLLAMA_URL}/api/embeddings",
|
89 |
json={"model": model, "prompt": text}
|
90 |
)
|
|
|
98 |
async def chat(model: str, message: str, system: str = "You are a helpful chatbot."):
|
99 |
"""Chat with the model while maintaining context."""
|
100 |
try:
|
101 |
+
response = requests.post(
|
102 |
f"{OLLAMA_URL}/api/chat",
|
103 |
json={"model": model, "messages": [{"role": "system", "content": system}, {"role": "user", "content": message}]}
|
104 |
)
|