Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo没跑起来 #47

Open
XingchenMengxiang opened this issue Sep 24, 2024 · 3 comments
Open

demo没跑起来 #47

XingchenMengxiang opened this issue Sep 24, 2024 · 3 comments

Comments

@XingchenMengxiang
Copy link

在这个示例的demo中,代码编译没有通过,缺少com.wd.common.core.domain.R类。
可以给个R类的代码或者maven坐标引入吗?

package com.zhipu.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wd.common.core.domain.R;
import com.zhipu.oapi.ClientV4;
import com.zhipu.oapi.service.v4.deserialize.MessageDeserializeFactory;
import com.zhipu.oapi.service.v4.model.ChatCompletionRequest;
import com.zhipu.oapi.service.v4.model.ModelApiResponse;
import com.zhipu.oapi.service.v4.model.ModelData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
public class TestController {

private final static Logger logger = LoggerFactory.getLogger(TestController.class);
private static final String API_SECRET_KEY = System.getProperty("ZHIPUAI_API_KEY");

private static final ClientV4 client = new ClientV4.Builder(API_SECRET_KEY)
        .networkConfig(300, 100, 100, 100, TimeUnit.SECONDS)
        .connectionPool(new okhttp3.ConnectionPool(8, 1, TimeUnit.SECONDS))
        .build();
private static final ObjectMapper mapper = MessageDeserializeFactory.defaultObjectMapper();


@RequestMapping("/test")
public R<ModelData> test(@RequestBody ChatCompletionRequest chatCompletionRequest) {
    ModelApiResponse sseModelApiResp = client.invokeModelApi(chatCompletionRequest);

    return R.ok(sseModelApiResp.getData());
}

}

@Liangdi
Copy link

Liangdi commented Oct 16, 2024

确实,这个估计是技术人员或者公司内部用的库, 而且这个 demo 写的很不好,不明了, 按照demo 定义了这个 http 接口,至少也要给个调用示例

@Liangdi
Copy link

Liangdi commented Oct 16, 2024

这个 R 就是大多框架都会设计的 Result 类, 你自己可以直接返回 sseModelApiResp.getData() 的 json 数据就好了, 去掉那个 R 的依赖和相关代码

@zzlTim
Copy link

zzlTim commented Oct 20, 2024

这个 R 就是大多框架都会设计的 Result 类, 你自己可以直接返回 sseModelApiResp.getData() 的 json 数据就好了, 去掉那个 R 的依赖和相关代码

真的怪,最起码给个调用api的示例,现在请求数据怎么写也不清楚,还是说默认openai格式也没说,还得自己去看它定义的数据类型

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

No branches or pull requests

3 participants