Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Query] How to set up for local models #172

Closed
bharattrader opened this issue Sep 18, 2024 · 5 comments
Closed

[Query] How to set up for local models #172

bharattrader opened this issue Sep 18, 2024 · 5 comments

Comments

@bharattrader
Copy link

Hi ,
Sorry for this maybe n00b question, I generally serve models using llama.cpp, ollama or textgenui on OpenAI compatible interface. How can I set up e11, to make it hit these services?

Thanks,

@bharattrader
Copy link
Author

Got, and example examples/ollama_example.py, Thanks

@QueryType
Copy link

Just for completeness, there is a problem with the example code. So you should try:

def set_api():
    _ = load_dotenv(find_dotenv()) # read local .env file
    return os.environ['OPENAI_API_KEY']

set_api()

ell.models.ollama.register(base_url="http://10.0.0.4:7862/v1")
@ell.complex(model="mistral-nemo-q6-k:latest", temperature=0.7)
def chat_bot(message_history: List[Message]) -> List[Message]:
    return [
        ell.system("You are a friendly chatbot. Engage in casual conversation."),
    ] + message_history

@rosmur
Copy link

rosmur commented Sep 21, 2024

@QueryType why does the OPENAI_API_KEY need to be loaded for ollama to work??

@QueryType
Copy link

@QueryType why does the OPENAI_API_KEY need to be loaded for ollama to work??

You can just pass a dummy key.

import os
import ell.models
import ell.models.ollama
from openai import OpenAI
from dotenv import load_dotenv, find_dotenv
import ell


def set_api():
    _ = load_dotenv(find_dotenv()) # read local .env file
    return os.environ['OPENAI_API_KEY']

set_api()
LOCAL_MODEL = "llama3.1:latest"
LOCAL_URL = "http://10.0.0.4:7862/v1"
ell.models.ollama.register(base_url=LOCAL_URL)
ollama_local_client = OpenAI(base_url=LOCAL_URL, api_key="local-llm")

@ell.simple(model=LOCAL_MODEL, client=ollama_local_client, temperature=0.7)
def hello(name: str):
    """You are a helpful assistant.""" # System prompt
    return f"Say hello to {name}!" # User prompt

greeting = hello("QueryType")
print(greeting)

@rosmur
Copy link

rosmur commented Sep 22, 2024

Hmm that still doesnt explain why you need load anything at all for OPENAI when you are using Ollama..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants