Spaces:
Sleeping
Sleeping
File size: 1,270 Bytes
1649601 61dcba5 f013b22 61dcba5 1649601 61dcba5 1649601 f013b22 61dcba5 f013b22 61dcba5 f013b22 1649601 f013b22 61dcba5 f013b22 61dcba5 1649601 61dcba5 f013b22 61dcba5 1649601 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import os
from huggingface_hub import InferenceClient
from langchain_community.tools import DuckDuckGoSearchRun
import config
def callWebSearch(query):
return DuckDuckGo(query)
def callLLM(query):
if "LOCALLLM" in os.environ:
return callLocalLLM(query)
else:
return callHfInferenceClientLLM(query)
def DuckDuckGo(query):
search_tool = DuckDuckGoSearchRun()
results = search_tool.invoke(query)
return results
def callLocalLLM(query):
response = OllamaChat(model=os.environ["LOCALLLM"], messages=[ { 'role': 'user', 'content': query } ])
return response['message']['content']
def callHfInferenceClientLLM(query):
client = InferenceClient(config.hfMoldel)
response = client.chat.completions.create(
messages = [ {"role": "user", "content": query } ],
stream=False, max_tokens=1024 )
return response.choices[0].message.content
if __name__ == "__main__":
os.environ["LOCALLLM"] = "llama3.2"
from ollama import chat as OllamaChat
response = callLLM("What is the capital of France?")
print(response)
response = callWebSearch("who is the president of France")
print(response)
response = callHfInferenceClientLLM("What is the capital of France?")
print(response) |