Skip to content

Commit

Permalink
fix: update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuridea committed Dec 8, 2023
1 parent 1c87041 commit 79d2555
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,80 @@ Install-Package Aeex.LLMService.Baidu.ErnieVilg

## 使用

1.`ConfigureService`方法中添加依赖注入

```
public void ConfigureServices(IServiceCollection services, IConfiguration config){
//....
// Ensure HttpContext injected. It will be accessed in Chat service.
services.AddHttpContextAccessor();
// inject image storage provider
services.AddTransient<IImageStorageProvider, LocalImageStorageProvider>();
// inject chat data provider
services.AddTransient<IChatDataProvider<BaiduWenxinMessage>, ChatDataProvider<BaiduWenxinMessage>>();
// inject baidu api service
services.AddWenxinworkshop(config);
services.AddErnieVilg(config);
//...
}
```

2. Have fun!

```
/// <summary>
/// 集成百度AI类api
/// </summary>
[ApiVersion("1.0")]
[ApiController]
[Route("api/v{version:apiVersion}/baidu")]
[ApiExplorerSettings(GroupName = "百度大模型")]
public class BaiduApiController(
IAIChatApiService<ChatRequest, ChatApiResponse> baiduApiService,
IAIPaintApiService<PaintApplyRequest, PaintResultResponse> ernieVilgApiService) : ControllerBase
{
private readonly IAIChatApiService<ChatRequest, ChatApiResponse> _apiService = baiduApiService;
private readonly IAIPaintApiService<PaintApplyRequest, PaintResultResponse> _ernieVilgApiService = ernieVilgApiService;
/// <summary>
/// 发起文心一言大模型对话
/// </summary>
/// <param name="request">The request.</param>
/// <returns></returns>
[HttpPost("chat")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(typeof(ChatApiResponse), 200)]
[AppExceptionInterceptor(ReturnCode = -100001, ApiVersion = "1.0")]
public async Task Chat(ChatRequest request)
{
await _apiService.Chat(request);
}
/// <summary>
/// 文生图
/// <para>封装文生图api以及回调获取生成图片api</para>
/// </summary>
/// <param name="request">The request.</param>
/// <returns></returns>
[HttpPost("text2img")]
[ProducesResponseType(typeof(PaintResultResponse), 200)]
public async Task<IActionResult> ApplyText2Img(PaintApplyRequest request)
{
var result = await _ernieVilgApiService.Text2Image(request);
Response.BuildAIGeneratedResponseFeature();
return Ok(result);
}
}
```



## 支持的模型

`LLMService` 支持的语言模型列表如下:
Expand Down
2 changes: 2 additions & 0 deletions src/LLMServiceHub/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public void ConfigureServices(IServiceCollection services)
));
});


// Ensure HttpContext injected. It will be accessed in Chat service.
services.AddHttpContextAccessor();


Expand Down

0 comments on commit 79d2555

Please sign in to comment.