[Python] How to integrate OpenAI API into my code?

Discussão em 'Python' iniciado por Stack, Fevereiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    Stack Overflow Question: Connecting OpenAI API to Converso in Replit – Not Working with process_document_with_openai

    Summary of the Problem:

    I’m integrating OpenAI’s latest API model into my Converso project (running on Replit), which provides real-time AI-powered responses during live sales calls and job interviews. The goal is to use OpenAI for answering both general knowledge questions and questions based on uploaded documents.

    However, when calling the OpenAI API via process_document_with_openai, the response does not return the expected answer. Instead, I keep getting the message:

    “While I’m currently using local AI capabilities, I can help you with general knowledge and guidance. For more detailed or specific information, please try again when the full service is restored.”


    This suggests that the API is not being called properly, or the system is defaulting to a fallback response instead of using OpenAI’s API.

    What I’ve Tried So Far: 1. Ensured API Key is Set Correctly: • Verified that the OpenAI API key is correctly stored in the environment variables. • Manually tested the API key using a direct API request via Postman, and it worked fine. 2. Checked API Call in process_document_with_openai: • Added logging to confirm whether process_document_with_openai is being executed. • Logs show no errors, but the expected response from OpenAI isn’t returned. 3. Confirmed API Endpoint & Model: • Using the latest OpenAI model (gpt-4-turbo). • Called openai.ChatCompletion.create() directly in a separate test file, and it worked. • Still, the integration inside Converso doesn’t return responses from OpenAI. 4. Checked Routing Logic: • Ensured that general knowledge questions are routed to OpenAI and document-based questions are routed to process_document_with_openai. • It seems like all queries are defaulting to a local AI response instead of calling OpenAI.

    My Question:

    How can I ensure that process_document_with_openai properly routes requests to OpenAI’s API and retrieves the correct response instead of defaulting to a fallback message? • Are there specific Replit settings or API configurations that might be blocking external API calls? • Could there be a misconfiguration in how OpenAI requests are handled in Replit’s environment? • Is there a way to debug Replit’s API call routing to confirm whether the request is actually reaching OpenAI?

    I’d appreciate any guidance on debugging this issue and ensuring OpenAI is properly integrated!

    Continue reading...

Compartilhe esta Página