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

Draft: New models interface #621

Open
2 tasks
Mini256 opened this issue Feb 7, 2025 · 1 comment
Open
2 tasks

Draft: New models interface #621

Mini256 opened this issue Feb 7, 2025 · 1 comment

Comments

@Mini256
Copy link
Member

Mini256 commented Feb 7, 2025

TODO

  • Using LiteLLM as the universal interface to call LLM / Embedding Model / Reranker Model
  • Provide more flexible model configuration methods
    • Configure the model provider (credentials) instead of the model in the settings.
    • Resolve the model using provider_name + model_name.
    • Allow override the model configurations on the calling side, such as: temperature, max_token.

Current State

  • When supporting a new model provider, we not only need to add the LlamaIndex dependency but also check its compatibility with DSPy.
  • Since Autoflow didn't maintain a list of supported models, the users need to enter the exact model name in the input field rather than selecting from a list.
  • Even if adding two models from the same provider, the users still have to go through the credentials configuration process again.

Why LiteLLM

  • LiteLLM has an active open-source community, making it more timely and easier to adapt to new models.
  • LiteLLM supports a comprehensive range of API endpoints, including Text Completions, Chat Completions, Embeddings, and the Rerank endpoint.
  • DSPy has already integrated LiteLLM as a unified interface layer for connecting to LLMs.

Sample Code

Using LLM

llm = LLM(
  model="openai/gpt4o",
  api_key=env.OPENAI_API_KEY
)
llm.completion(
  messages=[
    {
       "role": "system",
       "content": "Your are a TiDB expert"
    },
    {
       "role": "user",
       "content": "Does TiDB support Vector Search?"
    }
  ]
)

Get LLM from config

llm_config = kb.config.llm
llm = resolve_llm(
  provider=llm_config.provider
  model=llm_config.model
)

Convert to DSPy LM for use

lm = llm.as_dspy_lm()
qa = dspy.ChainOfThought('question -> answer')
response = qa(question="What is TiDB?")
print(response.answer)
@sykp241095
Copy link
Member

How about opening a new branch for refactor this?

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

2 participants