Skip to content

Commit

Permalink
hard-coded base url fixed microsoft#116
Browse files Browse the repository at this point in the history
  • Loading branch information
tricktreat committed Apr 10, 2023
1 parent 82d1516 commit c6e60fc
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ curl --location 'http://localhost:8004/tasks' \
We provide a user-friendly web page. After starting `awesome_chat.py` in a server mode, you can run the commands to communicate with Jarvis in your browser:

- you need to install `nodejs` and `npm` first.
- [ IMPORTANT ] if you are running the web client on another machine, you need set `http://{LAN_ip_of_the_server}:{port}/` to `web/src/api/hugginggpt.ts@Line=9`.
- [ IMPORTANT ] if you are running the web client on another machine, you need set `http://{LAN_IP_of_the_server}:{port}/` to `BASE_URL` of `web/src/config/index.ts`.
- if you want to use the video generation feature, you need to compile `ffmpeg` manually with H.264.
- you can switch to ChatGPT by `double click` on the setting icon!

Expand Down
2 changes: 1 addition & 1 deletion server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ num_candidate_models: 5
max_description_length: 100
proxy: # optional: your proxy server "http://ip:port"
http_listen:
host: 0.0.0.0 # if you use web as the client, please set `http://{LAN_ip_of_the_server}:{port}/` to @web/src/api/hugginggpt.ts line 9
host: 0.0.0.0 # if you use web as the client, please set `http://{LAN_IP_of_the_server}:{port}/` to `BASE_URL` of `web/src/config/index.ts`.
port: 8004
local_inference_endpoint:
host: localhost
Expand Down
2 changes: 1 addition & 1 deletion server/lite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ num_candidate_models: 5
max_description_length: 100
proxy: # optional: your proxy server "http://ip:port"
http_listen:
host: 0.0.0.0 # if you use web as the client, please set `http://{LAN_ip_of_the_server}:{port}/` to @web/src/api/hugginggpt.ts line 9
host: 0.0.0.0 # if you use web as the client, please set `http://{LAN_IP_of_the_server}:{port}/` to `BASE_URL` of `web/src/config/index.ts`.
port: 8004
logit_bias:
parse_task: 0.1
Expand Down
3 changes: 0 additions & 3 deletions server/run_gradio_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ def add_text(messages, message):
def bot(messages):
if len(OPENAI_KEY) == 0 or not OPENAI_KEY.startswith("sk-"):
return messages
# response = requests.post("http://localhost:8004/hugginggpt", json={"messages": all_messages, "openaikey": OPENAI_KEY})
# message = response.json()["message"]
# print(message)
message = chat_huggingface(all_messages, OPENAI_KEY)["message"]
image_urls, audio_urls, video_urls = extract_medias(message)
add_message(message, "assistant")
Expand Down
3 changes: 2 additions & 1 deletion web/src/api/hugginggpt.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { CleanChatMessage } from "@/types";
import axios, { AxiosError } from "axios";
import BASE_URL from "@/config";

const model = "gpt-3.5-turbo";

axios.defaults.headers.post["Content-Type"] = "application/json";

export async function hugginggpt(messageList: CleanChatMessage[], apiKey: string, dev: boolean) {
var endpoint = "http://localhost:8004/hugginggpt" // if you run the server on another machine, change this to the IP address
var endpoint = `${BASE_URL}/hugginggpt`
try {
const response = await axios({
url: endpoint,
Expand Down
3 changes: 3 additions & 0 deletions web/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const BASE_URL = "http://localhost:8004"

export default BASE_URL
15 changes: 8 additions & 7 deletions web/src/views/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { hugginggpt } from "@/api/hugginggpt";
import { chatgpt } from "@/api/chatgpt";
import Loading from "@/components/Loading.vue";
import promptCollection from "@/prompt";
import BASE_URL from "@/config";
let dev = ref(false);
let isChatgpt = ref(false);
Expand Down Expand Up @@ -102,8 +103,8 @@ const messageListMM = computed(() => {
start += seq_added_accum
end += seq_added_accum
const replace_str = `<span class="inline-flex items-baseline">
<a class="inline-flex text-sky-800 font-bold items-baseline" target="_blank" href="${image_urls[j].startsWith("http")?image_urls[j]:"http://localhost:8004"+image_urls[j]}">
<img src="${image_urls[j].startsWith("http")?image_urls[j]:"http://localhost:8004"+image_urls[j]}" alt="" class="inline-flex self-center w-5 h-5 rounded-full mx-1" />
<a class="inline-flex text-sky-800 font-bold items-baseline" target="_blank" href="${image_urls[j].startsWith("http")?image_urls[j]:""+image_urls[j]}">
<img src="${image_urls[j].startsWith("http")?image_urls[j]:BASE_URL+image_urls[j]}" alt="" class="inline-flex self-center w-5 h-5 rounded-full mx-1" />
<span class="mx-1">[Image]</span>
</a>
</span>`
Expand All @@ -112,7 +113,7 @@ const messageListMM = computed(() => {
content = content.slice(0, start) + replace_str + content.slice(end)
if(!image_urls[j].startsWith("http")){
image_urls[j] = "http://localhost:8004" + image_urls[j]
image_urls[j] = BASE_URL + image_urls[j]
}
}
}
Expand All @@ -130,7 +131,7 @@ const messageListMM = computed(() => {
start += seq_added_accum
end += seq_added_accum
const replace_str = `<span class="inline-flex items-baseline">
<a class="text-sky-800 inline-flex font-bold items-baseline" target="_blank" href="${audio_urls[j].startsWith("http")?audio_urls[j]:"http://localhost:8004"+audio_urls[j]}">
<a class="text-sky-800 inline-flex font-bold items-baseline" target="_blank" href="${audio_urls[j].startsWith("http")?audio_urls[j]:BASE_URL+audio_urls[j]}">
<img class="inline-flex self-center w-5 h-5 rounded-full mx-1" src="/audio.svg"/>
<span class="mx-1">[Audio]</span>
</a>
Expand All @@ -140,7 +141,7 @@ const messageListMM = computed(() => {
content = content.slice(0, start) + replace_str + content.slice(end)
if(!audio_urls[j].startsWith("http")){
audio_urls[j] = "http://localhost:8004" + audio_urls[j]
audio_urls[j] = BASE_URL + audio_urls[j]
}
}
}
Expand All @@ -158,7 +159,7 @@ const messageListMM = computed(() => {
start += seq_added_accum
end += seq_added_accum
const replace_str = `<span class="inline-flex items-baseline">
<a class="text-sky-800 inline-flex font-bold items-baseline" target="_blank" href="${video_urls[j].startsWith("http")?video_urls[j]:"http://localhost:8004"+video_urls[j]}">
<a class="text-sky-800 inline-flex font-bold items-baseline" target="_blank" href="${video_urls[j].startsWith("http")?video_urls[j]:BASE_URL+video_urls[j]}">
<img class="inline-flex self-center w-5 h-5 rounded-full mx-1" src="/video.svg"/>
<span class="mx-1">[video]</span>
</a>
Expand All @@ -168,7 +169,7 @@ const messageListMM = computed(() => {
content = content.slice(0, start) + replace_str + content.slice(end)
if(!video_urls[j].startsWith("http")){
video_urls[j] = "http://localhost:8004" + video_urls[j]
video_urls[j] = BASE_URL + video_urls[j]
}
}
}
Expand Down

0 comments on commit c6e60fc

Please sign in to comment.