Skip to content

Support for customization of webclient for OpenAI #609

Closed
@deepakn27

Description

@deepakn27

Bug description
Getting Error while doing chatClient.stream(prompt).

This only happens for chatClient.stream(prompt). My finding is it happens due to WebClient
CURL and chatClient.call(prompt) work fine.
Caused by: java.net.UnknownHostException: Failed to resolve 'api.openai.com' [A(1)]

Caused by: io.netty.resolver.dns.DnsNameResolverTimeoutException: [19766: /192.168.29.1:53] DefaultDnsQuestion(api.openai.com. IN A) query '19766' via UDP timed out after 5000 milliseconds (no stack trace available)

Environment
Please provide as many details as possible: Spring AI version - 0.8.1,
Java version - 17,
vector store - SimpleVectorStore (InMemory)

Steps to reproduce
call below method for any prompt.
Prompt prompt = new Prompt("tell me something about java");
return this.chatClient.stream(prompt).map((ChatResponse chatResponse) -> {

        if (!isValidResponse(chatResponse)) {
            logger.warn("ChatResponse or the result output is null!");
            return "";
        }

        AssistantMessage assistantMessage = chatResponse.getResult().getOutput();

        this.chatHistory.addMessage(chatId, assistantMessage);

        return (assistantMessage.getContent() != null) ? assistantMessage.getContent() : "";
    });

Expected behavior
Code should stream proper llm response

Minimal Complete Reproducible example
Prompt prompt = new Prompt("tell me something about java");
return this.chatClient.stream(prompt).map((ChatResponse chatResponse) -> {

        if (!isValidResponse(chatResponse)) {
            logger.warn("ChatResponse or the result output is null!");
            return "";
        }

        AssistantMessage assistantMessage = chatResponse.getResult().getOutput();

        this.chatHistory.addMessage(chatId, assistantMessage);

        return (assistantMessage.getContent() != null) ? assistantMessage.getContent() : "";
    });

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions