|
1 | | -import math |
2 | 1 | from typing import Any, Dict, List, Optional |
3 | 2 |
|
4 | 3 | from graphgen.bases.base_llm_wrapper import BaseLLMWrapper |
|
9 | 8 | class OllamaClient(BaseLLMWrapper): |
10 | 9 | """ |
11 | 10 | Requires a local or remote Ollama server to be running (default port 11434). |
12 | | - The /api/chat endpoint in Ollama 0.1.24+ supports stream=False |
13 | | - and raw=true to return logprobs, but the top_logprobs field is not yet implemented by the official API. |
| 11 | + The top_logprobs field is not yet implemented by the official API. |
14 | 12 | """ |
15 | 13 |
|
16 | 14 | def __init__( |
@@ -99,29 +97,7 @@ async def generate_topk_per_token( |
99 | 97 | history: Optional[List[Dict[str, str]]] = None, |
100 | 98 | **extra: Any, |
101 | 99 | ) -> List[Token]: |
102 | | - messages = [] |
103 | | - if self.system_prompt: |
104 | | - messages.append({"role": "system", "content": self.system_prompt}) |
105 | | - if history: |
106 | | - messages.extend(history) |
107 | | - messages.append({"role": "user", "content": text}) |
108 | | - |
109 | | - response = await self.client.chat( |
110 | | - model=self.model_name, |
111 | | - messages=messages, |
112 | | - options={ |
113 | | - "temperature": self.temperature, |
114 | | - "top_p": self.top_p, |
115 | | - "num_predict": 5, |
116 | | - "logprobs": True, |
117 | | - }, |
118 | | - stream=False, |
119 | | - ) |
120 | | - |
121 | | - tokens = [] |
122 | | - for item in response.get("message", {}).get("logprobs", {}).get("content", []): |
123 | | - tokens.append(Token(item["token"], math.exp(item["logprob"]))) |
124 | | - return tokens |
| 100 | + raise NotImplementedError("Ollama API does not support per-token top-k yet.") |
125 | 101 |
|
126 | 102 | async def generate_inputs_prob( |
127 | 103 | self, text: str, history: Optional[List[Dict[str, str]]] = None, **extra: Any |
|
0 commit comments