- coder
- java
- spring全家桶
- python
- mongo,mysql,redis...
Java client library for OpenAI API.Full support for all OpenAI API models including Completions, Chat, Edits, Embeddings, Audio, Files, Assistants-v2, Images, Moderations, Batch, and Fine-tuning.
License: MIT License
Hi, Is there any plan to package the latest version of maven dependencies to upload to remote maven central repository.
This will be handy for me to add dependency packages to the project, thanks again!
For example, purpose
I am the maintainer of this open-source library, and I developed it based on the openai Java library. Currently, the JDK 8 version is no longer suitable for my own needs. I have the idea of upgrading to a higher version of the JDK to use more of its features
However, this idea depends on the thoughts of the people using this library. I hope those who see this issue can provide their own opinions
Structured Outputs via tools is available by setting strict: true within your function definition.
Hi @Lambdua, I'm using your library specially for the Assistants API. Since yesterday the added a parallel_tool_calls
param, I am getting this error:
Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "parallel_tool_calls" (class com.theokanning.openai.assistants.run.Run), not marked as ignorable...
What I did locally as a workaround was to make the JsonUtil internal Mapper a bit more robust, so that unknown properties would not make the parsing fail:
private static class ObjectMapperHolder {
private static final ObjectMapper MAPPER = new ObjectMapper();
static {
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
MAPPER.setPropertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE);
}
}
What do you think of this change?
There are multiple settings related to function/tool in the code: ChatFunction/AssistantFunction/ChatFunctionDynamic
应该共享一个配置好的ObjectMapper实例。
I use this API for a Discord bot with ChatGPT
After switching from the gpt-3.5-turbo model to the gpt-4o, sometimes an error started appearing during requests
The latest assistant supports image recognition
a new refusal string value on API responses which allows developers to programmatically detect if the model has generated a refusal instead of output matching the schema. When the response does not include a refusal and the model’s response has not been prematurely interrupted (as indicated by finish_reason), then the model’s response will reliably produce valid JSON matching the supplied schema.
Hey, thanks for taking over the project and continuing development on it.
Can you please add File Search tool and provide some examples?
Thanks in advance!
OpenAiService service = getOpenAiService();
ThreadRequest threadRequest = ThreadRequest.builder().build();
Thread thread = service.createThread(threadRequest);
return thread.getId();
springboot 3.1.0,jdk18
service应该默认支持重试机制
目前想要自定义注入拦截器比较复杂,应该在构造函数上添加更灵活的定制化需求
delete assistant message endpoint
现在api包里面没有呢
Customizing File Search settings
The newes change support customize how the file_search tool chunks your data and how many chunks it returns to the model context.
When using this code:
The messages returned from listMessages
don't have an ImageUrl object. They only have a MessageContent
object with type image_url
but no image_url
. The Assistant Playground does show that this data is returned from the API when listing thread messages.
Is it possibly because the messages returned from the Threads API are being coerced to Assistant MessageContent which doesn't cater for image_url
?
微调的endpoint参数,和最新版openai有一些差异.不是最新的
developers can now supply a JSON Schema via json_schema, a new option for the response_format parameter.
https://openai.com/index/introducing-structured-outputs-in-the-api
ChatCompleteRequest的属性:
@JsonSerialize(using = ChatCompletionRequestFunctionCall.Serializer.class)
@JsonDeserialize(using = ChatCompletionRequestFunctionCall.Deserializer.class)
Object functionCall;
使用时不够友好,应该转为显示类型,减少学习成本
Using the new FunctionDefinition
returns this on azure's gpt-4-turbo
"error": {
"message": "1 validation error for Request\nbody -> tools\n extra fields not permitted (type=value_error.extra)",
"type": "invalid_request_error",
"param": null,
"code": null
}
Looking at the converted JSON (I used ObjectMapper().writeValueAsString
so I am not sure if it's accurate)
{
"type": "function",
"function": {
"name": "wolframAlpha",
"description": "Computes mathematical expressions using WolframAlpha",
"parameters": {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Wolfram Alpha Function",
"type": "object",
"additionalProperties": false,
"properties": {
"input": {
"type": "string"
}
}
}
}
}
seems like azure doesn't support the "$schema"
, "title"
, "aditionalProperties"
fields as I can't find these in any documentation
another limitation with the new FunctionDefinition
is that it doesn't allow parameterless functions, the parameters field is optional and can be omitted
Omitting parameters defines a function with an empty parameter list.
现有的token工具好像只能统计实际文字所使用的token,但搜索文件使用的token没有被统计。有什么办法统计搜索文件使用的token数量吗?
我在尝试将接收到的JSON请求体反序列化为ChatCompletionRequest对象时遇到了问题。尽管我发送的请求数据格式看起来是正确的,但是反序列化过程没有成功。
请求示例
{
"topP": 1,
"temperature": 1,
"maxTokens": 2500,
"messages": [
{
"role": "system",
"content": "你好"
},
{
"role": "user",
"content": [
{
"type": "text",
"text": "识别这张图片"
},
{
"type": "image_url",
"imageUrl": {
"url": "https://img.baigonglian.com/open_platform/generate/1ad71539c74715cfceb1c6b2634e9bf1.png"
}
}
]
}
],
"model": "gpt-4o",
"frequencyPenalty": 0.6299999952316284
}
看异常应该是有些字段的序列化方式没设置对。
重现测试用例:
public class ChatCompletionExample {
private static final String BASE_URL = "https://api.openai.com/v1/";
private static final String API_KEY = "sk-1234567890";
private static final ObjectMapper objectMapper = new ObjectMapper();
public static void main(String[] args) throws JsonProcessingException {
String json = "{\"model\":\"gpt-4o-mini\",\"max_tokens\":150,\"response_format\":{\"type\":\"json_object\"},\"messages\":[{\"role\":\"system\",\"content\":\"You are a helpful assistant and you should reply in JSON format.\"},{\"role\":\"user\",\"content\":\"What is your name?\"}]}";
ChatCompletionRequest completionRequest = objectMapper.readValue(json, ChatCompletionRequest.class);
OpenAiService openAiService = new OpenAiService(API_KEY, BASE_URL);
ChatCompletionResult completionResult = openAiService.createChatCompletion(completionRequest);
System.out.println(completionResult);
}
}
报了如下异常:
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.theokanning.openai.completion.chat.ChatResponseFormat` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{"model":"gpt-4o-mini","max_tokens":150,"response_format":{"type":"json_object"},"messages":[{"role":"system","content":"You are a helpful assistant and you should reply in JSON format."},{"role":"user","content":"What is your name?"}]}"; line: 1, column: 60] (through reference chain: com.theokanning.openai.completion.chat.ChatCompletionRequest["response_format"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1733)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1358)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1420)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:352)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:314)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4730)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3677)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3645)
at example.ChatCompletionExample.main(ChatCompletionExample.java:21)
0.20.1
<dependency>
<groupId>io.github.lambdua</groupId>
<artifactId>service</artifactId>
<version>0.20.1</version>
</dependency>
异常信息:
java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.PropertyNamingStrategies
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.theokanning.openai.service.OpenAiService.defaultObjectMapper(OpenAiService.java:180)
at com.theokanning.openai.service.OpenAiService.<clinit>(OpenAiService.java:82)
ChatFunction
,FunctionExecutor
and ChatFunctionDynamic
这几个类以及AssistantFunction导致目前api注入function变得很混乱
As of 0.21.0, it looks like the parameter max_num_results is not available in FileSearchTool. Is this on the roadmap?
See https://platform.openai.com/docs/api-reference/assistants/createAssistant#assistants-createassistant-tools (request body, under tools -> FileSearch)
I think there is no documentation about how to send Image from ByteArray or Stream... but I think the ChatGPT allow this ? It is possible to send by url or "text"... what is a text image ??
Thank you for this great API !
Is it possible to implement GET in the threads API to find out all the threads you created.
It seems to be possible also if not officially documented using the following example:
def list_threads(api_key):
response = requests.get(
'https://api.openai.com/v1/threads?order=desc&limit=20',
headers={
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_key}',
'OpenAI-Beta': 'assistants=v1'
}
)
if response.status_code == 200:
return response.json()['data']
return None
Please consider this new feature in the next release. Thanks
Please add support for the new parameter parallel_tool_calls
(see https://community.openai.com/t/new-api-feature-disable-parallel-function-calling-via-parallel-tool-calls-false/805405, https://platform.openai.com/docs/api-reference/runs/createThreadAndRun and https://platform.openai.com/docs/api-reference/chat/create).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.