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

Understanding the question/answering process and its costs #24

Open
bbscout opened this issue Apr 13, 2023 · 7 comments
Open

Understanding the question/answering process and its costs #24

bbscout opened this issue Apr 13, 2023 · 7 comments

Comments

@bbscout
Copy link

bbscout commented Apr 13, 2023

Can someone explain to me what the process is behind the scenes when calling the OpenAI API?

I understand how embedding works (#1). But how much text from the embedding is included in following requests? And why there are for example 2 requests for one question or even 5 when using ChatOpenAI?

Example:

I tried simple question (in Czech because my embeddings are in Czech) "How old must the camp leader be at least?". The chain made two API calls with 5565 tokens in total. And the response was "The minimum age for the camp leader is 18 according to Junák – český skaut." It's not very cost effective when using text-davinci. For one simple question I pay around 0,11 USD.

req

costs

I simply tried replace OpenAI() with ChatOpenAI() which uses gpt-3.5-turbo-0301. The chain made 5 requests (4,643 prompt + 278 completion = 4,921 tokens). The price is 10x lower and also less tokens are used.

chain = VectorDBQAWithSourcesChain.from_llm(llm=ChatOpenAI(temperature=0), vectorstore=store)

Is it possible to affect how long "embeddings" will be included in the request?

Thanks for any information.

@aabdelfattah
Copy link

I also made 2 trials which costed 0.8$ (~ 0.4$ per question).
I am wondering about your change, it doesn't seem as a one liner because also more stuff needs to be included . Can you please elaborate how did you replace OpenAI() with ChatOpenAI() ?

@lmsanch
Copy link

lmsanch commented Apr 19, 2023

Exactly the same experience for me.

@sfx101
Copy link

sfx101 commented Apr 21, 2023

Use a tool like Proxyman to get more insights.
image
And yes, the Langchain code in this particular repo makes two requests, 1 for a kind of summarizing the context from Faiss and the other for generating the answer.
As I said, Proxyman or Charles might be useful to get more insights on costs, tokens etc

@aabdelfattah
Copy link

Use a tool like Proxyman to get more insights. image And yes, the Langchain code in this particular repo makes two requests, 1 for a kind of summarizing the context from Faiss and the other for generating the answer. As I said, Proxyman or Charles might be useful to get more insights on costs, tokens etc

This is probably out of the context of the main question, but how did you get proxyman to decrypt https

I always get this

Retrying langchain.embeddings.openai.embed_with_retry.<locals>._embed_with_retry in 8.0 seconds as it raised APIConnectionError: Error communicating with OpenAI: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url:

@aabdelfattah
Copy link

I also made 2 trials which costed 0.8$ (~ 0.4$ per question). I am wondering about your change, it doesn't seem as a one liner because also more stuff needs to be included . Can you please elaborate how did you replace OpenAI() with ChatOpenAI() ?

Answering my own question: here is a commit which does the intended replacement

@sfx101
Copy link

sfx101 commented Apr 22, 2023

@yixin0829
Copy link

Weights and Biases also released it Prompts feature that supports langchain integration. https://docs.wandb.ai/guides/prompts/quickstart

Think it might be really helpful if you wanna try.

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

5 participants