Skip to content

feat: add openai api support and chunking#8

Merged
dearden merged 2 commits into
mainfrom
openai-api-and-chunking
Jul 6, 2026
Merged

feat: add openai api support and chunking#8
dearden merged 2 commits into
mainfrom
openai-api-and-chunking

Conversation

@dearden

@dearden dearden commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

As I've been adding stuff recently which all runs the same code to run requests on OpenAI API Compatible LLMs, I have added the functionality to genai utils.

This is mostly so we can keep things consistent like

  • Structured output (not supported atm but maybe could be added)
  • Logging

Specifically for this PR I have added:

  • A basic LLM class for running requests on an Open AI API compatible LLM
  • Functionality for chunking documents into chunks of sentences.

Pull request checklist

  • I have linked my PR to an issue
  • I’ve used conventional commits
  • I have used Claude to /review my PR, and reviewed any LLM generated code myself
  • Where appropriate, I have added or updated tests
  • Where appropriate, I have updated documentation to reflect my changes

@dearden dearden requested a review from dcorney June 25, 2026 11:46

@dcorney dcorney left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

def _is_model_loading(exception: BaseException) -> bool:
return (
isinstance(exception, openai.InternalServerError)
and exception.status_code == 503

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any risk that a 503/not responding might mean that something is long-term offline and not just still loading? Do we need a timeout for example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether it's worth getting rid of this behaviour. It was all so it worked on cloud run - because the model would wake up on your first request. Now we're just hosting models it's probably not necessary anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although saying that I don't think it does any harm. It does give up on retrying - and I suppose 503 errors are something where it's always worth trying a retry.

"""
We frequently end up chunking input sentences when we do things with Gen AI.
This has become replicated across multiple projects,
so we made some laughably simple helper functions here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All true, but remember this is an open-source library :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just thought it was worth the context for why chunking functionality was in there

@dearden dearden merged commit f1d8e65 into main Jul 6, 2026
2 checks passed
@dearden dearden deleted the openai-api-and-chunking branch July 6, 2026 15:02
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

Successfully merging this pull request may close these issues.

2 participants