Kamil Lewandowski
Kamil Lewandowski•5mo ago

ai API works differently.

I want to create an action that calls openAI API (perplexity in this case). When I use postman I get normal answer based on real life data (like asking about some stock price). When I use fetch from convex server I always get answer that model doesn't have access to the internet. What is wrong here?
No description
No description
5 Replies
ballingt
ballingt•5mo ago
By openAI API do you mean OpenAPI? That's interesting! It looks like you're comparing the responses, can you compare the cookies and headers that you send? If you're using your credentials it's surprising behavior would differ, but if you're making free requests it's reasonable that Perplexity would rate limit free accounts differently based on IP
Kamil Lewandowski
Kamil LewandowskiOP•5mo ago
I was looking for some ai api that has access to the internet and gives up to date info. convex action: try { const response = await fetch("https://api.perplexity.ai/chat/completions", { method: "POST", headers: { "Accept": "application/json", "Content-Type": "application/json", "Authorization": "Bearer " + token, }, body: JSON.stringify({ model: 'llama-3.1-sonar-small-128k-online', messages: [ {role: 'system', content: 'Be precise and concise.'}, {role: 'user', content: reminderDescription} ] }), }); const result = await response.json(); __ curl from postman curl --request POST \ --url https://api.perplexity.ai/chat/completions \ --header 'accept: application/json' \ --header 'authorization: Bearer pplx-...' \ --header 'content-type: application/json' \ --data ' { "model": "llama-3.1-sonar-small-128k-online", "messages": [ { "role": "system", "content": "Be precise and concise." }, { "role": "user", "content": "How many stars are there in our galaxy?" } ] } '
ballingt
ballingt•5mo ago
That's interesting! Can you try hitting Postman or similar with these to ensure they match? They look the same to me
Kamil Lewandowski
Kamil LewandowskiOP•5mo ago
yeah, a few request later, answers are changed, so finally the one from convex is fine. Sorry for confusion.
ballingt
ballingt•5mo ago
and that's LLMs! 🤣

Did you find this page helpful?