nd2py.search.llmsr.api package#
Submodules#
nd2py.search.llmsr.api.deepseek_api module#
nd2py.search.llmsr.api.gemini_api module#
nd2py.search.llmsr.api.llm_api module#
nd2py.search.llmsr.api.llm_result module#
Utilities for llmsr module
- class nd2py.search.llmsr.api.llm_result.LLMResult(gen: Iterator)[source]#
Bases:
objectWrapper for LLM generator that captures the return value.
This class wraps a generator and provides convenient property access to the result dictionary after the generator is exhausted.
The key is using yield from to delegate to the inner generator, which automatically captures the return value via StopIteration.value.
Example
>>> api = OpenAIAPI(model='gpt-4o-mini') >>> result = api("Hello") # Returns LLMResult >>> for content in result: ... print(content) >>> print(result.usage) # Access via property >>> print(result.contents) # List of generated contents
- property usage: dict#
Token usage statistics.
- property messages: list#
Input messages.
- property response: dict#
Raw API response.
- property responses: list#
Raw API responses (for n>1 generations).
- property contents: list#
List of generated content strings.
nd2py.search.llmsr.api.manual_api module#
nd2py.search.llmsr.api.openai_api module#
- class nd2py.search.llmsr.api.openai_api.OpenAIAPI(model='gpt-5-mini', max_tokens=4096, n=1, temperature=1.0, top_p=1.0, use_chat_completions=False)[source]#
Bases:
LLMAPI- supported_models = ['gpt-4o-mini', 'gpt-5-mini']#
- __init__(model='gpt-5-mini', max_tokens=4096, n=1, temperature=1.0, top_p=1.0, use_chat_completions=False)[source]#
- create_responses(messages: List | str, **kwargs) Generator[str, None, Dict][source]#
OpenAI 的最新 API, 建议新项目使用这个接口 (https://platform.openai.com/docs/guides/migrate-to-responses) 但看起来它还缺了一些功能 (比如 n parameter), 而且也无法缓存 gpt-4o-mini 的 prompt token, 所以依然保留了 create_chat_completions 接口