|
1 | 1 | --- |
2 | | -title: 2024.01.2 |
| 2 | +title: 2024.01.3 (latest) |
3 | 3 | --- |
4 | 4 |
|
5 | | -| Release version | Release Time | |
6 | | -|:---------------:|:------------:| |
7 | | -| `2024.01.2` | `2024-03-10` | |
| 5 | +| 发布版本 | 发布时间 | |
| 6 | +|:-----------:|:------------:| |
| 7 | +| `2024.01.3` | `2024-05-17` | |
8 | 8 |
|
9 | 9 | ## OpenAi |
10 | 10 |
|
11 | 11 | --- |
12 | 12 |
|
13 | | -- Create thread |
14 | | -- Retrieve thread |
15 | | -- Modify thread |
16 | | -- Delete thread |
| 13 | +- 支持新模型 `gpt-4o` |
| 14 | + |
| 15 | +### Google Gemini |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +- 支持简单对话 |
| 20 | + |
| 21 | + ```java |
| 22 | + try (GoogleClient client = GoogleClient.builder() |
| 23 | + .apiKey(token) |
| 24 | + .build()) { |
| 25 | + PartEntity part = PartEntity.builder() |
| 26 | + .text("Hello, Open AI Java SDK!") |
| 27 | + .build(); |
| 28 | + ObjectEntity object = ObjectEntity.builder() |
| 29 | + .parts(Lists.newArrayList(part)) |
| 30 | + .build(); |
| 31 | + ChatEntity chat = ChatEntity.builder() |
| 32 | + .contents(Lists.newArrayList(object)) |
| 33 | + .build(); |
| 34 | + |
| 35 | + ChatResponse response = client.createChatCompletions(chat); |
| 36 | + response.getCandidates() |
| 37 | + .forEach(item -> item.getContent() |
| 38 | + .getParts() |
| 39 | + .forEach(value -> log.info(value.getText()))); |
| 40 | + } |
| 41 | + ``` |
| 42 | + |
| 43 | +- 支持连续对话 |
| 44 | + |
| 45 | + ```java |
| 46 | + List<ObjectEntity> contents = Lists.newArrayList(); |
| 47 | + PartEntity part = PartEntity.builder() |
| 48 | + .text("你好,我叫小明") |
| 49 | + .build(); |
| 50 | + ObjectEntity object = ObjectEntity.builder() |
| 51 | + .parts(Lists.newArrayList(part)) |
| 52 | + .build(); |
| 53 | + contents.add(object); |
| 54 | + ChatEntity chat = ChatEntity.builder() |
| 55 | + .contents(contents) |
| 56 | + .build(); |
| 57 | + ChatResponse response = client.createChatCompletions(chat); |
| 58 | + response.getCandidates() |
| 59 | + .forEach(item -> item.getContent() |
| 60 | + .getParts() |
| 61 | + .forEach(value -> { |
| 62 | + log.info(value.getText()); |
| 63 | + |
| 64 | + contents.add(ObjectEntity.builder() |
| 65 | + .role(RoleModel.MODEL) |
| 66 | + .parts(Lists.newArrayList(PartEntity.builder() |
| 67 | + .text(value.getText()) |
| 68 | + .build())) |
| 69 | + .build()); |
| 70 | + })); |
| 71 | + |
| 72 | + ObjectEntity newObject = ObjectEntity.builder() |
| 73 | + .parts(Lists.newArrayList(PartEntity.builder() |
| 74 | + .text("我刚刚说了什么") |
| 75 | + .build())) |
| 76 | + .build(); |
| 77 | + contents.add(newObject); |
| 78 | + ChatEntity newChat = ChatEntity.builder() |
| 79 | + .contents(contents) |
| 80 | + .build(); |
| 81 | + client.createChatCompletions(newChat); |
| 82 | + ``` |
| 83 | + |
| 84 | +- 支持流式响应 |
| 85 | + |
| 86 | + ```java |
| 87 | + // 构建客户端 |
| 88 | + CountDownLatch countDownLatch = new CountDownLatch(1); |
| 89 | + ConsoleEventSourceListener listener = ConsoleEventSourceListener.builder() |
| 90 | + .countDownLatch(countDownLatch) |
| 91 | + .build(); |
| 92 | + GoogleClient client = GoogleClient.builder() |
| 93 | + .apiKey(ResourceUtils.getValue("google.token")) |
| 94 | + .listener(listener) |
| 95 | + .build(); |
| 96 | + |
| 97 | + List<ObjectEntity> contents = Lists.newArrayList(); |
| 98 | + PartEntity part = PartEntity.builder() |
| 99 | + .text("帮我写一万字的作文") |
| 100 | + .build(); |
| 101 | + ObjectEntity object = ObjectEntity.builder() |
| 102 | + .parts(Lists.newArrayList(part)) |
| 103 | + .build(); |
| 104 | + contents.add(object); |
| 105 | + ChatEntity chat = ChatEntity.builder() |
| 106 | + .contents(contents) |
| 107 | + .build(); |
| 108 | + client.createChatCompletions(chat); |
| 109 | + try { |
| 110 | + countDownLatch.await(); |
| 111 | + } |
| 112 | + catch (InterruptedException e) { |
| 113 | + log.error("Interrupted while waiting", e); |
| 114 | + } |
| 115 | + ``` |
0 commit comments