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

feat(llms): Add streaming support to OpenAI #196

Merged
merged 1 commit into from
Nov 6, 2023
Merged

feat(llms): Add streaming support to OpenAI #196

merged 1 commit into from
Nov 6, 2023

Conversation

davidmigloz
Copy link
Owner

@davidmigloz davidmigloz commented Nov 6, 2023

Relates to #4

Example:

final promptTemplate = PromptTemplate.fromTemplate(
  'List the numbers from 1 to {max_num} in order without any spaces or commas',
);
final llm = OpenAI(apiKey: openaiApiKey);
const stringOutputParser = StringOutputParser<String>();
final chain = promptTemplate.pipe(llm).pipe(stringOutputParser);

final stream = chain.stream({'max_num': '9'});

String content = '';
await for (final res in stream) {
  content += res;
  print(content);
}

will print:


123
12345
1234567
123456789

@davidmigloz davidmigloz self-assigned this Nov 6, 2023
@davidmigloz davidmigloz added t:enhancement New feature or request c:llms Models and integrations. p:langchain_openai langchain_openai package. labels Nov 6, 2023
@davidmigloz davidmigloz merged commit b21fcb3 into main Nov 6, 2023
1 check passed
@davidmigloz davidmigloz deleted the streaming branch November 6, 2023 21:09
KennethKnudsen97 pushed a commit to KennethKnudsen97/langchain_dart that referenced this pull request Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c:llms Models and integrations. p:langchain_openai langchain_openai package. t:enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant