|
|
|
@ -11,7 +11,7 @@ from ollama import ( |
|
|
|
ChatResponse, |
|
|
|
ChatResponse, |
|
|
|
Options, |
|
|
|
Options, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
import backoff |
|
|
|
import env_manager |
|
|
|
import env_manager |
|
|
|
from colorprinter.print_color import * |
|
|
|
from colorprinter.print_color import * |
|
|
|
|
|
|
|
|
|
|
|
@ -179,6 +179,16 @@ class LLM: |
|
|
|
) |
|
|
|
) |
|
|
|
return options |
|
|
|
return options |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@backoff.on_exception( |
|
|
|
|
|
|
|
backoff.expo, |
|
|
|
|
|
|
|
(ResponseError, TimeoutError), |
|
|
|
|
|
|
|
max_tries=3, |
|
|
|
|
|
|
|
factor=2, |
|
|
|
|
|
|
|
base=10, |
|
|
|
|
|
|
|
on_backoff=lambda details: print_yellow( |
|
|
|
|
|
|
|
f"Retrying due to error: {details['exception']}" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
def _call_remote_api( |
|
|
|
def _call_remote_api( |
|
|
|
self, model, tools, stream, options, format, headers, think=False |
|
|
|
self, model, tools, stream, options, format, headers, think=False |
|
|
|
): |
|
|
|
): |
|
|
|
@ -198,6 +208,16 @@ class LLM: |
|
|
|
) |
|
|
|
) |
|
|
|
return response |
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@backoff.on_exception( |
|
|
|
|
|
|
|
backoff.expo, |
|
|
|
|
|
|
|
(ResponseError, TimeoutError), |
|
|
|
|
|
|
|
max_tries=3, |
|
|
|
|
|
|
|
factor=2, |
|
|
|
|
|
|
|
base=10, |
|
|
|
|
|
|
|
on_backoff=lambda details: print_yellow( |
|
|
|
|
|
|
|
f"Retrying due to error: {details['exception']}" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
async def _call_remote_api_async( |
|
|
|
async def _call_remote_api_async( |
|
|
|
self, model, tools, stream, options, format, headers, think=False |
|
|
|
self, model, tools, stream, options, format, headers, think=False |
|
|
|
): |
|
|
|
): |
|
|
|
@ -287,7 +307,17 @@ class LLM: |
|
|
|
if not self.chat: |
|
|
|
if not self.chat: |
|
|
|
self.messages = [self.messages[0]] |
|
|
|
self.messages = [self.messages[0]] |
|
|
|
return response_obj.message |
|
|
|
return response_obj.message |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@backoff.on_exception( |
|
|
|
|
|
|
|
backoff.expo, |
|
|
|
|
|
|
|
(ResponseError, TimeoutError), |
|
|
|
|
|
|
|
max_tries=3, |
|
|
|
|
|
|
|
factor=2, |
|
|
|
|
|
|
|
base=10, |
|
|
|
|
|
|
|
on_backoff=lambda details: print_yellow( |
|
|
|
|
|
|
|
f"Retrying due to error: {details['exception']}" |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
async def _call_local_ollama_async(self, model, stream, temperature, think=False): |
|
|
|
async def _call_local_ollama_async(self, model, stream, temperature, think=False): |
|
|
|
"""Call the local Ollama instance asynchronously (using a thread pool).""" |
|
|
|
"""Call the local Ollama instance asynchronously (using a thread pool).""" |
|
|
|
import ollama |
|
|
|
import ollama |
|
|
|
|