Skip to content

Commit 86448c7

Browse files
committed
feat: enhance LlamaEdgeClient initialization with additional parameters and update run_mcp_server example
1 parent 5bfdeef commit 86448c7

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

app/llm_client.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
import os
22
import json
3-
from typing import Dict, List, Optional, Union
4-
from openai import OpenAI
3+
import requests
4+
from typing import List, Dict, Any, Optional
5+
from openai import OpenAI # Add this import
56

67
class LlamaEdgeClient:
78
"""Client for interacting with LlamaEdge OpenAI-compatible API"""
89

9-
def __init__(self, api_key=None):
10+
def __init__(self, api_key=None, api_base=None, model=None, embed_model=None):
11+
"""Initialize LlamaEdgeClient with API credentials
12+
13+
Args:
14+
api_key: API key for LLM service
15+
api_base: Base URL for API (overrides LLM_API_BASE env var)
16+
model: Model name (overrides LLM_MODEL env var)
17+
embed_model: Embedding model name (overrides LLM_EMBED_MODEL env var)
18+
"""
1019
self.api_key = api_key or os.getenv("LLM_API_KEY")
1120
if not self.api_key:
1221
raise ValueError("API key is required")
1322

14-
# Use environment variables with defaults
15-
self.base_url = os.getenv("LLM_API_BASE", "http://localhost:8080/v1")
16-
self.llm_model = os.getenv("LLM_MODEL", "Qwen2.5-Coder-3B-Instruct")
17-
self.llm_embed_model = os.getenv("LLM_EMBED_MODEL", "gte-Qwen2-1.5B-instruct") # Fixed variable name
23+
# Use provided parameters with fallback to environment variables
24+
self.base_url = api_base or os.getenv("LLM_API_BASE", "http://localhost:8080/v1")
25+
self.llm_model = model or os.getenv("LLM_MODEL", "Qwen2.5-Coder-3B-Instruct")
26+
self.llm_embed_model = embed_model or os.getenv("LLM_EMBED_MODEL", "gte-Qwen2-1.5B-instruct") # Fixed variable name
1827

1928
# Initialize OpenAI client with custom base URL
2029
self.client = OpenAI(

app/vector_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import uuid
33
from typing import Dict, List, Optional, Any
44
from qdrant_client import QdrantClient
5-
from qdrant_client.http import models
5+
from qdrant_client.http import models as qmodels
6+
from qdrant_client import models # Add this import
67

78
class QdrantStore:
89
"""Interface for Qdrant vector database"""

examples/run_mcp_server.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ def main():
1818
llm_api_base = os.getenv("LLM_API_BASE", "https://coder.gaia.domains/v1")
1919
llm_model = os.getenv("LLM_MODEL", "Qwen2.5-Coder-32B-Instruct-Q5_K_M")
2020

21-
llm_client = LlamaEdgeClient(api_key=api_key, api_base=llm_api_base, model=llm_model)
22-
23-
# Get Qdrant host and port from environment variables (for Docker)
21+
# Get Qdrant connection details
2422
qdrant_host = os.getenv("QDRANT_HOST", "localhost")
2523
qdrant_port = int(os.getenv("QDRANT_PORT", "6333"))
2624

25+
llm_client = LlamaEdgeClient(api_key=api_key, api_base=llm_api_base, model=llm_model)
2726
vector_store = QdrantStore(embedding_size=llm_embed_size, host=qdrant_host, port=qdrant_port)
2827
vector_store.create_collection("project_examples")
2928
vector_store.create_collection("error_examples")

0 commit comments

Comments
 (0)