Skip to content

Commit 051d1cd

Browse files
committed
add translate server and client
1 parent ee26e3e commit 051d1cd

File tree

5 files changed

+1810
-27
lines changed

5 files changed

+1810
-27
lines changed

CMakeLists.txt

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,31 @@ add_library(ax_translate SHARED
4343
src/utils/memory_utils.cpp
4444
)
4545

46-
add_executable(test_llm tests/test_llm.cpp)
47-
target_link_libraries(test_llm PRIVATE ax_translate dl)
48-
49-
add_executable(test_translate tests/test_translate.cpp)
50-
target_link_libraries(test_translate PRIVATE ax_translate dl)
46+
function(compile_test_case test_name)
47+
add_executable(${test_name} tests/${test_name}.cpp)
48+
target_link_libraries(${test_name} PRIVATE ax_translate dl)
49+
install(TARGETS ${test_name}
50+
LIBRARY DESTINATION lib
51+
ARCHIVE DESTINATION lib
52+
RUNTIME DESTINATION bin
53+
)
54+
endfunction(compile_test_case)
55+
56+
compile_test_case(test_llm)
57+
compile_test_case(test_translate)
58+
compile_test_case(translate_svr)
59+
60+
add_executable(translate_cli tests/translate_cli.cpp)
61+
install(TARGETS translate_cli
62+
LIBRARY DESTINATION lib
63+
ARCHIVE DESTINATION lib
64+
RUNTIME DESTINATION bin
65+
)
5166

5267
install(TARGETS ax_translate
5368
LIBRARY DESTINATION lib
5469
ARCHIVE DESTINATION lib
5570
RUNTIME DESTINATION bin
5671
)
5772
install(DIRECTORY include DESTINATION include)
58-
install(DIRECTORY pytranslate DESTINATION lib/)
59-
60-
# target_link_libraries(ax_translate PRIVATE sentencepiece dl)
61-
62-
63-
# add_executable(test_translate tests/test_translate.cpp)
64-
# target_link_libraries(test_translate PRIVATE ax_translate)
65-
66-
# install(TARGETS ax_translate
67-
# LIBRARY DESTINATION lib
68-
# ARCHIVE DESTINATION lib
69-
# RUNTIME DESTINATION bin
70-
# )
71-
72-
# install(TARGETS test_translate
73-
# LIBRARY DESTINATION lib
74-
# ARCHIVE DESTINATION lib
75-
# RUNTIME DESTINATION bin
76-
# )
77-
78-
# install(FILES include/ax_translate.h include/ax_devices.h DESTINATION include)
73+
install(DIRECTORY pytranslate DESTINATION lib/)

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@
3333
output: 你好,世界!
3434
```
3535

36-
## Gradio
36+
### Gradio
3737
```shell
3838
python gradio_example.py --config ../build/config.json
3939
```
4040
![chs.png](pytranslate/chs.png)
4141
![jpn.png](pytranslate/jpn.png)
4242
![thai.png](pytranslate/thai.png)
4343

44+
### HTTP API
45+
#### 启动服务
46+
```shell
47+
./translate_svr -c config.json -h 0.0.0.0 -p 8080
48+
listen on http://0.0.0.0:8080
49+
```
50+
#### 调用服务
51+
```shell
52+
./translate_cli -h 0.0.0.0 -p 8080 -i "hello,world!" -t target_chs
53+
{"input":"hello,world!","output":"你好,世界!","target":"target_chs"}
54+
你好,世界!
55+
```
4456
## 社区
4557
QQ 群: 139953715

0 commit comments

Comments
 (0)