Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, or to ban temporarily or permanently any
contributor for other behaviors that they deem inappropriate, threatening,
offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

This Code of Conduct also applies outside the project spaces when the Project
Steward has a reasonable belief that an individual's behavior may have a
negative impact on the project or its community.

## Conflict Resolution

We do not believe that all conflict is bad; healthy debate and disagreement
often yield positive results. However, it is never okay to be disrespectful or
to engage in behavior that violates the project’s code of conduct.

If you see someone violating the code of conduct, you are encouraged to address
the behavior directly with those involved. Many issues can be resolved quickly
and easily, and this gives people more control over the outcome of their
dispute. If you are unable to resolve the matter for any reason, or if the
behavior is threatening or harassing, report it. We are dedicated to providing
an environment where participants feel welcome and safe.

Reports should be directed to *[PROJECT STEWARD NAME(s) AND EMAIL(s)]*, the
Project Steward(s) for *[PROJECT NAME]*. It is the Project Steward’s duty to
receive and address reported violations of the code of conduct. They will then
work with a committee consisting of representatives from the Open Source
Programs Office and the Z.ai Open Source Strategy team.

We will investigate every complaint, but you may not receive a direct response.
We will use our discretion in determining when and how to follow up on reported
incidents, which may range from not taking action to permanent expulsion from
the project and project-sponsored spaces. We will notify the accused of the
report and provide them an opportunity to discuss it before any action is taken.
The identity of the reporter will be omitted from the details of the report
supplied to the accused. In potentially harmful situations, such as ongoing
harassment or threats to anyone's safety, we may take action without notice.

## Attribution

This Code of Conduct is adapted from the Contributor Covenant, version 1.4,
available at
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
54 changes: 54 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# How to contribute

We'd love to accept your patches and contributions to this project.

## Contribution process

### Code reviews

All submissions, including submissions by project members, require review. We
use GitHub pull requests for this purpose. Consult
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
information on using pull requests.

### Contributor Guide

You may follow these steps to contribute:

1. **Fork the official repository.** This will create a copy of the official repository in your own account.
2. **Sync the branches.** This will ensure that your copy of the repository is up-to-date with the latest changes from the official repository.
3. **Work on your forked repository's feature branch.** This is where you will make your changes to the code.
4. **Commit your updates on your forked repository's feature branch.** This will save your changes to your copy of the repository.
5. **Submit a pull request to the official repository's main branch.** This will request that your changes be merged into the official repository.
6. **Resolve any linting errors.** This will ensure that your changes are formatted correctly.

Here are some additional things to keep in mind during the process:

- **Test your changes.** Before you submit a pull request, make sure that your changes work as expected.
- **Be patient.** It may take some time for your pull request to be reviewed and merged.


### Environment Setup
For running unit tests, set up your environment variables with your API credentials:

```bash
export ZHIPUAI_BASE_URL=https://open.bigmodel.cn/api/paas/v4/ # Default ZhipuAI API endpoint
export ZHIPUAI_API_KEY=your_api_key_here # Replace with your actual API key
```

> ⚠️ **Note**: Running tests will consume a small amount of tokens from your API account.

### Dependencies

This SDK uses the following core dependencies:

| Library | Version |
|---------|----------|
| OkHttp | 3.14.9 |
| Java JWT | 4.2.2 |
| Jackson | 2.11.3 |
| Retrofit2 | 2.9.0 |


Have Fun!
---
132 changes: 67 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,79 @@
# 智谱大模型开放接口SDK
# ZhipuAI Open Platform Java SDK

智谱[开放平台](http://open.bigmodel.cn/howuse/platformintroduced)大模型接口Java SDK(Big Model API SDK in
Java),让开发者更便捷的调用智谱开放API
[![Maven Central](https://img.shields.io/maven-central/v/cn.bigmodel.openapi/oapi-java-sdk.svg)](https://search.maven.org/artifact/cn.bigmodel.openapi/oapi-java-sdk)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Java](https://img.shields.io/badge/java-1.8%2B-orange.svg)](https://www.oracle.com/java/)

## 简介
- <font color="red">**java sdk仍在开发测试阶段,有bug请留言联系**</font>
- 对所有接口进行了类型封装,无需查阅API文档即可完成接入
[中文文档](README_CN.md)

## 安装
The official Java SDK for [ZhipuAI Open Platform](http://open.bigmodel.cn/howuse/platformintroduced) Big Model API, enabling developers to easily integrate ZhipuAI's powerful AI capabilities into their Java applications.

- 运行环境:JDK1.8+
- maven坐标
```
<dependency>
<groupId>cn.bigmodel.openapi</groupId>
<artifactId>oapi-java-sdk</artifactId>
<version>release-V4-2.3.4</version>
</dependency>
```
- 运行单元测试依赖您环境变量中的APIKey和BaseUrl信息,建议您提前设置好环境变量;运行过程中会消耗APIKey对应账户下的少量token
```
export ZHIPUAI_BASE_URL=https://open.bigmodel.cn/api/paas/v4/ # 默认智谱开放平台API地址
export ZHIPUAI_API_KEY=6082424a4dxxxxxxxxxxb9d.svyyyyyyyyyK8K # 替换为你自己的APIKey
```
### 依赖信息
## ✨ Features

- 🚀 **Type-safe API**: All interfaces are fully type-encapsulated, no need to consult API documentation
- 🔧 **Easy Integration**: Simple and intuitive API design for quick integration
- ⚡ **High Performance**: Built with modern Java libraries for optimal performance
- 🛡️ **Secure**: Built-in authentication and token management
- 📦 **Lightweight**: Minimal dependencies for easy project integration

```text
okhttp_3.14.9
java-jwt_4.2.2
jackson_2.11.3
retrofit2_2.9.0
## 📦 Installation

### Requirements
- Java 1.8 or higher
- Maven or Gradle

### Maven
Add the following dependency to your `pom.xml`:

```xml
<dependency>
<groupId>cn.bigmodel.openapi</groupId>
<artifactId>oapi-java-sdk</artifactId>
<version>release-V4-2.3.4</version>
</dependency>
```
## 使用
- 调用流程:
1. 使用APIKey创建Client
2. 调用Client对应的成员方法
- [V4Test.java](src/test/java/com/zhipu/oapi/V4Test.java)有完整的demo示例,请替换自己的ApiKey进行测试

### 📋 Dependencies

This SDK uses the following core dependencies:

> SDK提供了ClientV4的构造器,此方法可以在创建Client时进行配置,可配置项如下:
| Library | Version |
|---------|----------|
| OkHttp | 3.14.9 |
| Java JWT | 4.2.2 |
| Jackson | 2.11.3 |
| Retrofit2 | 2.9.0 |


- enableTokenCache:是否开启token缓存,开启后会缓存token,减少token请求次数
- networkConfig:设置连接超时、读取超时、写入超时、ping间隔、ping超时时间
- connectionPool:设置连接池
## 🚀 Quick Start

```
String API_SECRET_KEY = "your api";
### Basic Usage

1. **Create a Client** with your API key
2. **Call the desired API methods**

For complete examples, see [V4Test.java](src/test/java/com/zhipu/oapi/V4Test.java). Remember to replace the API key with your own.

### Client Configuration

The SDK provides a flexible `ClientV4` builder for customizing your client:

**Configuration Options:**
- `enableTokenCache()`: Enable token caching to reduce token requests
- `networkConfig()`: Configure connection, read, write timeouts, and ping intervals
- `connectionPool()`: Set up connection pooling

```java
String API_SECRET_KEY = "your_api_key_here";
private static final ClientV4 client = new ClientV4.Builder(API_SECRET_KEY)
.enableTokenCache()
.networkConfig(30, 10, 10, 10, TimeUnit.SECONDS)
.connectionPool(new okhttp3.ConnectionPool(8, 1, TimeUnit.SECONDS))
.build();

```

### spring Controller 示例
## 💡 Examples

### Spring Boot Integration

```java
package com.zhipu.controller;
Expand Down Expand Up @@ -100,34 +118,18 @@ public class TestController {

```

## 📈 Release Notes

## 升级内容

#### release-V4-2.3.0
- 知识库业务
- 智能助手业务
- 增加embedding-3支持
For detailed release notes and version history, please see [Release-Note.md](Release-Note.md).

#### release-V4-2.2.0
- 重构代码
- 高级检索接口
- codegeex接口
- 视频生成功能
## 📄 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

#### release-V4-2.1.0
- 增加拓展报文序列化工具类
- 增加测试样例
- 修改为使用api key鉴权
- 统一通信客户端
- 删除部分序列化框架依赖
- 增加批处理API
## 🤝 Contributing

#### release-V4-2.0.2
- readTimeOut时间设置为300s
- 修改测试demo中apiKey命名
We welcome contributions! Please feel free to submit a Pull Request.

## 📞 Support

#### release-V4-2.0.1
- 统一client4构造apikey入参
- 延长token过期时间
For questions and support, please visit the [ZhipuAI Open Platform](http://open.bigmodel.cn/) or check our documentation.
Loading