Find answers from the community

Updated 2 months ago

hi i am new to python and i need your

hi i am new to python and i need your help on something.

I want to make a chatbot using my own data but it always uses the text-davinci model, how can I change this model?

I am sending the code. thanks

Code :

import openai
from llama_index import VectorStoreIndex, SimpleDirectoryReader, Document, StorageContext, load_index_from_storage
import os

os.environ['OPENAI_API_KEY'] = 'token'
openai.api_key = os.environ['OPENAI_API_KEY']

documents = SimpleDirectoryReader('textFiles').load_data()

text_list = [documents[0].text]
documents = [Document(t) for t in text_list]

index = VectorStoreIndex.from_documents(documents)

index.storage_context.persist()

storage_context = StorageContext.from_defaults(persist_dir="./storage")
index = load_index_from_storage(storage_context)
query_engine = index.as_query_engine()

while True:
user_input = input("Please enter a question: ")
if user_input.lower() == 'exit':
break
response = query_engine.query(user_input)
print(response)
L
k
6 comments
You can use the service context to change the model

Plain Text
from langchain.chat_models import ChatOpenAI
from llama_index import LLMPredictor, ServiceContext

service_context = ServiceContext.from_defaults(llm_predictor=LLMPredictor(llm=ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0)))

index = load_index_from_storage(storage_context, service_context=service_context)
Hello again,
Thank you very much for your help.
In the example you gave, https://api.openai.com/v1/chat/completions sends a request here, I want it to send a request here https://api.openai.com/v1/completions and I want it to use text-ada-001 as a model.

Can you help me? @Logan M
from llama_index.llms import OpenAI llm = OpenAI(temperature=0, model="text-davinci-002") service_context = ServiceContext.from_defaults(llm=llm)

When I use this example written in the document, I get this error:
File "main.py", line 5, in <module> from llama_index.llms import OpenAI ModuleNotFoundError: No module named 'llama_index.llms' @Logan M
The docs are updated for a big release, but the release is not out yet πŸ˜… use a pinned version of the docs for now

https://gpt-index.readthedocs.io/en/v0.6.38/
Why do you want to use text Ada 001 for generating text? It will be quite bad...

In any case, you can use

Plain Text
from langchain.llms import OpenAI


And use that instead of ChatOpenAI
Add a reply
Sign up and join the conversation on Discord