Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

add support for Google Cloud (#2175)

黄腾5decdde18255
diff --git a/api/apps/llm_app.py b/api/apps/llm_app.py
index 26cbd45760..c50c0a5727 100644
--- a/api/apps/llm_app.py
+++ b/api/apps/llm_app.py
@@ -150,6 +150,14 @@ def add_llm():
llm_name = req["llm_name"]
api_key = '{' + f'"fish_audio_ak": "{req.get("fish_audio_ak", "")}", ' \
f'"fish_audio_refid": "{req.get("fish_audio_refid", "59cb5986671546eaa6ca8ae6f29f6d22")}"' + '}'
+ elif factory == "Google Cloud":
+ llm_name = req["llm_name"]
+ api_key = (
+ "{" + f'"google_project_id": "{req.get("google_project_id", "")}", '
+ f'"google_region": "{req.get("google_region", "")}", '
+ f'"google_service_account_key": "{req.get("google_service_account_key", "")}"'
+ + "}"
+ )
else:
llm_name = req["llm_name"]
api_key = req.get("api_key","xxxxxxxxxxxxxxx")
diff --git a/conf/llm_factories.json b/conf/llm_factories.json
index 698443efd3..891eccf524 100644
--- a/conf/llm_factories.json
+++ b/conf/llm_factories.json
@@ -3352,6 +3352,13 @@
"model_type": "rerank"
}
]
+ },
+ {
+ "name": "Google Cloud",
+ "logo": "",
+ "tags": "LLM",
+ "status": "1",
+ "llm": []
}
]
}
diff --git a/rag/llm/__init__.py b/rag/llm/__init__.py
index 54bfc67ff5..c3b30b1c97 100644
--- a/rag/llm/__init__.py
+++ b/rag/llm/__init__.py
@@ -107,6 +107,7 @@ ChatModel = {
"XunFei Spark": SparkChat,
"BaiduYiyan": BaiduYiyanChat,
"Anthropic": AnthropicChat,
+ "Google Cloud": GoogleChat,
}
diff --git a/rag/llm/chat_model.py b/rag/llm/chat_model.py
index 9569daa24e..500b08b87e 100644
--- a/rag/llm/chat_model.py
+++ b/rag/llm/chat_model.py
@@ -701,9 +701,13 @@ class GeminiChat(Base):
self.model = GenerativeModel(model_name=self.model_name)
self.model._client = _client
+
def chat(self,system,history,gen_conf):
+ from google.generativeai.types import content_types
+
if system:
- history.insert(0, {"role": "user", "parts": system})
+ self.model._system_instruction = content_types.to_content(system)
+
if 'max_tokens' in gen_conf:
gen_conf['max_output_tokens'] = gen_conf['max_tokens']
for k in list(gen_conf.keys()):
@@ -725,8 +729,10 @@ class GeminiChat(Base):
return "**ERROR**: " + str(e), 0
def chat_streamly(self, system, history, gen_conf):
+ from google.generativeai.types import content_types
+
if system:
- history.insert(0, {"role": "user", "parts": system})
+ self.model._system_instruction = content_types.to_content(system)
if 'max_tokens' in gen_conf:
gen_conf['max_output_tokens'] = gen_conf['max_tokens']
for k in list(gen_conf.keys()):
@@ -1257,3 +1263,154 @@ class AnthropicChat(Base):
yield ans + "\n**ERROR**: " + str(e)
yield total_tokens
+
+
+class GoogleChat(Base):
+ def __init__(self, key, model_name, base_url=None):
+ from google.oauth2 import service_account
+ import base64
+
+ key = json.load(key)
+ access_token = json.loads(
+ base64.b64decode(key.get("google_service_account_key", ""))
+ )
+ project_id = key.get("google_project_id", "")
+ region = key.get("google_region", "")
+
+ scopes = ["https://www.googleapis.com/auth/cloud-platform"]
+ self.model_name = model_name
+ self.system = ""
+
+ if "claude" in self.model_name:
+ from anthropic import AnthropicVertex
+ from google.auth.transport.requests import Request
+
+ if access_token:
+ credits = service_account.Credentials.from_service_account_info(
+ access_token, scopes=scopes
+ )
+ request = Request()
+ credits.refresh(request)
+ token = credits.token
+ self.client = AnthropicVertex(
+ region=region, project_id=project_id, access_token=token
+ )
+ else:
+ self.client = AnthropicVertex(region=region, project_id=project_id)
+ else:
+ from google.cloud import aiplatform
+ import vertexai.generative_models as glm
+
+ if access_token:
+ credits = service_account.Credentials.from_service_account_info(
+ access_token
+ )
+ aiplatform.init(
+ credentials=credits, project=project_id, location=region
+ )
+ else:
+ aiplatform.init(project=project_id, location=region)
+ self.client = glm.GenerativeModel(model_name=self.model_name)
+
+ def chat(self, system, history, gen_conf):
+ if system:
+ self.system = system
+
+ if "claude" in self.model_name:
+ if "max_tokens" not in gen_conf:
+ gen_conf["max_tokens"] = 4096
+ try:
+ response = self.client.messages.create(
+ model=self.model_name,
+ messages=history,
+ system=self.system,
+ stream=False,
+ **gen_conf,
+ ).json()
+ ans = response["content"][0]["text"]
+ if response["stop_reason"] == "max_tokens":
+ ans += (
+ "...\nFor the content length reason, it stopped, continue?"
+ if is_english([ans])
+ else "······\n由于长度的原因,回答被截断了,要继续吗?"
+ )
+ return (
+ ans,
+ response["usage"]["input_tokens"]
+ + response["usage"]["output_tokens"],
+ )
+ except Exception as e:
+ return ans + "\n**ERROR**: " + str(e), 0
+ else:
+ self.client._system_instruction = self.system
+ if "max_tokens" in gen_conf:
+ gen_conf["max_output_tokens"] = gen_conf["max_tokens"]
+ for k in list(gen_conf.keys()):
+ if k not in ["temperature", "top_p", "max_output_tokens"]:
+ del gen_conf[k]
+ for item in history:
+ if "role" in item and item["role"] == "assistant":
+ item["role"] = "model"
+ if "content" in item:
+ item["parts"] = item.pop("content")
+ try:
+ response = self.client.generate_content(
+ history, generation_config=gen_conf
+ )
+ ans = response.text
+ return ans, response.usage_metadata.total_token_count
+ except Exception as e:
+ return "**ERROR**: " + str(e), 0
+
+ def chat_streamly(self, system, history, gen_conf):
+ if system:
+ self.system = system
+
+ if "claude" in self.model_name:
+ if "max_tokens" not in gen_conf:
+ gen_conf["max_tokens"] = 4096
+ ans = ""
+ total_tokens = 0
+ try:
+ response = self.client.messages.create(
+ model=self.model_name,
+ messages=history,
+ system=self.system,
+ stream=True,
+ **gen_conf,
+ )
+ for res in response.iter_lines():
+ res = res.decode("utf-8")
+ if "content_block_delta" in res and "data" in res:
+ text = json.loads(res[6:])["delta"]["text"]
+ ans += text
+ total_tokens += num_tokens_from_string(text)
+ except Exception as e:
+ yield ans + "\n**ERROR**: " + str(e)
+
+ yield total_tokens
+ else:
+ self.client._system_instruction = self.system
+ if "max_tokens" in gen_conf:
+ gen_conf["max_output_tokens"] = gen_conf["max_tokens"]
+ for k in list(gen_conf.keys()):
+ if k not in ["temperature", "top_p", "max_output_tokens"]:
+ del gen_conf[k]
+ for item in history:
+ if "role" in item and item["role"] == "assistant":
+ item["role"] = "model"
+ if "content" in item:
+ item["parts"] = item.pop("content")
+ ans = ""
+ try:
+ response = self.model.generate_content(
+ history, generation_config=gen_conf, stream=True
+ )
+ for resp in response:
+ ans += resp.text
+ yield ans
+
+ except Exception as e:
+ yield ans + "\n**ERROR**: " + str(e)
+
+ yield response._chunks[-1].usage_metadata.total_token_count
diff --git a/requirements.txt b/requirements.txt
index 0f21366069..2d08924411 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -85,6 +85,7 @@ tiktoken==0.6.0
torch==2.3.0
transformers==4.38.1
umap==0.1.1
+vertexai==1.64.0
volcengine==1.0.146
voyageai==0.2.3
webdriver_manager==4.0.1
diff --git a/requirements_arm.txt b/requirements_arm.txt
index 01b9ce0e3f..cf0b4c504f 100644
--- a/requirements_arm.txt
+++ b/requirements_arm.txt
@@ -167,3 +167,4 @@ scholarly==1.7.11
deepl==1.18.0
psycopg2-binary==2.9.9
tabulate==0.9.0
+vertexai==1.64.0
\ No newline at end of file
diff --git a/web/src/assets/svg/llm/google-cloud.svg b/web/src/assets/svg/llm/google-cloud.svg
new file mode 100644
index 0000000000..2f7870552c
--- /dev/null
+++ b/web/src/assets/svg/llm/google-cloud.svg
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1725003802154" class="icon" viewBox="0 0 6536 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4319" xmlns:xlink="http://www.w3.org/1999/xlink" width="1276.5625" height="200"><path d="M768.860432 268.528163h36.948079l105.31657-105.316571 5.164004-44.73045C720.275163-54.549329 421.126644-35.857092 248.096173 160.156829 200.020031 214.560693 165.181193 279.365296 146.125295 349.479366c11.709923-4.800341 24.729029-5.600398 36.948078-2.181973l210.633142-34.766105s10.691668-17.746715 16.292066-16.655729c93.679381-102.9164 251.363307-114.917253 359.589175-27.347396h-0.727324z" fill="#EA4335" p-id="4320"></path><path d="M1061.172102 349.479366c-24.219902-89.169969-73.896157-169.321117-142.991974-230.561829l-147.792315 147.792315c62.404432 50.985439 97.970595 127.863627 96.443214 208.451168v26.25641c72.659706 0 131.572981 58.913275 131.572981 131.572981s-58.913275 131.572981-131.572981 131.572981H603.685064l-26.25641 26.620073v157.829391l26.25641 26.25641h263.145963c188.958875 1.454649 343.369842-150.556147 344.82449-339.515022 0.872789-114.771788-55.640315-222.124867-150.483415-286.274878z" fill="#4285F4" p-id="4321"></path><path d="M340.17544 973.59642h263.145962V762.963279H340.17544c-18.764969 0-37.239008-4.073017-54.331131-11.855388l-36.948079 11.491725-106.043895 105.316571-9.23702 36.948079c59.422402 44.948647 132.009376 69.095816 206.560125 68.732154z" fill="#34A853" p-id="4322"></path><path d="M340.17544 290.347894C151.143833 291.438881-1.085161 445.558918 0.005826 634.590525c0.654592 105.534768 49.894453 204.887279 133.609489 269.182754l152.592656-152.592655c-66.186519-29.893032-95.643156-107.862206-65.750124-174.048725S328.320053 481.488742 394.506572 511.381774c29.165708 13.164571 52.512821 36.584417 65.750124 65.750125l152.592656-152.592656c-64.877335-84.951488-165.82996-134.627743-272.673912-134.191349z" fill="#FBBC05" p-id="4323"></path><path d="M1912.214363 826.53143c-91.57014 1.163719-179.57639-34.984303-243.871865-100.152568-66.404716-62.404432-103.49826-149.828823-102.334541-240.962568-1.090987-91.133745 36.002557-178.485404 102.334541-240.962569 64.004546-65.822857 152.083529-102.698203 243.871865-101.970878 87.424391-1.163719 171.721287 32.80233 233.907522 94.26124l-65.750124 66.913843c-45.021379-43.566731-105.534768-67.42297-168.157398-66.550181-65.677392-0.800057-128.736416 26.038213-173.685062 73.896158-46.694225 46.330563-72.441509 109.75325-71.350523 175.503373-0.58186 65.0228 25.165424 127.499964 71.350523 173.321401 95.134029 94.8431 248.526742 96.661411 345.915476 4.073017 29.020243-31.711343 46.766958-72.150579 50.621778-114.917253h-221.761205v-94.55217H2227.073089c3.054762 19.055899 4.291214 38.329995 3.709355 57.676824 3.927552 80.660274-25.310889 159.429505-80.951204 218.05185-61.895305 64.368208-148.301442 99.425243-237.616877 96.370481z m729.506357-62.840827c-87.497123 83.860501-225.543291 83.860501-313.040414 0-42.403012-41.093828-65.531927-98.043327-63.931814-157.029334-1.600114-58.986008 21.601534-115.935507 63.931814-157.029335 87.569856-83.642304 225.470559-83.642304 313.040414 0 42.330279 41.093828 65.531927 98.043327 63.931814 157.029335 1.527381 59.05874-21.819732 116.008239-64.295476 157.029334h0.363662z m-243.944598-61.677108c45.166844 48.294339 120.954045 50.767242 169.248384 5.527666 1.891043-1.818311 3.782087-3.636622 5.527665-5.527666 24.656297-25.529086 37.966333-59.858797 36.948079-95.352226 1.090987-35.566162-12.21905-70.114071-36.948079-95.715889-46.476028-48.439804-123.426948-50.11265-171.939484-3.636622-1.236451 1.163719-2.472903 2.40017-3.636622 3.636622-24.729029 25.601818-38.039065 60.149727-36.948078 95.715889-0.945522 35.49343 12.509979 69.895873 37.31174 95.352226h0.436395z m725.069678 61.677108c-87.497123 83.860501-225.543291 83.860501-313.040415 0-42.403012-41.093828-65.531927-98.043327-63.931813-157.029334-1.600114-58.986008 21.601534-115.935507 63.931813-157.029335 87.497123-83.860501 225.543291-83.860501 313.040415 0 42.330279 41.093828 65.531927 98.043327 63.931814 157.029335 1.672846 58.986008-21.528802 115.935507-63.931814 157.029334z m-243.871866-61.677108c45.166844 48.294339 120.954045 50.767242 169.248385 5.527666 1.891043-1.818311 3.782087-3.636622 5.527665-5.527666 24.656297-25.529086 37.966333-59.858797 36.948079-95.352226 1.090987-35.566162-12.21905-70.114071-36.948079-95.715889-46.476028-48.439804-123.426948-50.11265-171.866752-3.636622-1.236451 1.163719-2.472903 2.40017-3.636622 3.636622-24.729029 25.601818-38.039065 60.149727-36.948079 95.715889-0.945522 35.49343 12.509979 69.895873 37.311741 95.352226h0.363662z m560.185241 321.84104c-44.294055 1.381916-87.715321-12.437247-123.063286-39.202784a226.816109 226.816109 0 0 1-71.714184-90.915548l84.224163-35.129768c9.164287 21.528802 23.492578 40.439236 41.74842 55.058456 19.492293 15.710207 44.003125 24.001705 69.095817 23.27438 32.147738 1.963776 63.568151-10.182541 86.115207-33.238724 22.256126-26.83827 33.238724-61.313446 30.693089-96.079551v-31.784076h-3.345693c-28.583848 33.893316-71.423254 52.367356-115.644577 49.894453-56.07671 0.145465-109.680517-23.128915-147.792314-64.295476-41.312025-40.802898-64.150011-96.734143-63.204489-154.847361-1.018254-58.404148 21.819732-114.699055 63.204489-155.938348 38.039065-41.312025 91.642872-64.804603 147.792314-64.659137 23.492578-0.072732 46.766958 5.164003 68.00483 15.128347 18.401307 8.000568 34.766106 20.001421 48.076142 35.129767h3.345692v-35.129767h91.642873v393.555224c4.873073 62.913559-16.364799 125.099794-58.767811 171.866752-40.366503 38.620925-94.55217 59.276937-150.410682 57.313161z m6.691384-283.801974c31.92954 0.727324 62.549897-12.873642 83.496839-36.948079 22.765253-26.110945 34.838838-59.931529 33.602387-94.624902 1.381916-35.275233-10.618936-69.677676-33.602387-96.443214-20.946942-24.14717-51.567299-37.675403-83.496839-36.948078-32.80233-0.654592-64.295476 12.800909-86.478869 36.948078-24.438099 25.820016-37.748136 60.222459-36.948079 95.715889-0.727324 35.2025 12.509979 69.241281 36.948079 94.624902 22.037929 24.365367 53.531075 38.111798 86.478869 37.675404zM3811.331062 167.284608v645.936786h-96.443213V167.284608h96.443213z m264.600611 659.246822c-58.404148 1.527381-114.771788-21.383337-155.574686-63.204489-41.384757-41.45749-64.004546-98.116059-62.477164-156.665672-2.181973-58.695078 19.565026-115.790042 60.222459-158.193054 38.402727-40.439236 92.079267-62.840827 147.792314-61.74984 25.383621-0.29093 50.476312 4.654876 73.896158 14.401023 21.092407 8.509695 40.293771 21.092407 56.513104 36.948078 13.964628 13.455501 26.329143 28.438383 36.948079 44.73045 8.582428 13.746431 15.855672 28.220186 21.819732 43.203068l9.964344 25.165424L3969.451383 672.775055c18.328574 42.039349 60.586121 68.513957 106.407557 66.550181 44.294055 0.145465 85.387883-23.056183 108.298601-60.949783l73.896158 49.894453a242.722693 242.722693 0 0 1-70.98686 67.277505c-33.165992 20.946942-71.859649 31.711343-111.135166 30.984019z m-123.426948-226.561546l196.595781-81.678528c-6.036792-14.401023-16.873926-26.25641-30.693089-33.602387-15.419277-8.727893-32.875062-13.164571-50.621777-12.946374-30.038497 0.800057-58.622345 13.382769-79.423823 35.129768-25.238156 24.14717-38.402727 58.258683-35.857092 93.097521zM4770.308262 826.53143c-168.157398 2.909298-306.785425-131.063854-309.694723-299.221252-0.072732-4.073017-0.072732-8.218766 0.072733-12.291782-3.927552-168.157398 129.245543-307.585482 297.330208-311.513033 4.073017-0.072732 8.218766-0.072732 12.291782-0.072733 84.078699-2.618368 164.811705 33.311457 219.142837 97.5342l-53.240145 51.712764c-39.930109-50.258115-101.461752-78.405569-165.53903-75.787201-61.45891-1.381916-120.881313 22.401591-164.448043 65.750124-45.312309 45.603239-69.532211 108.007671-66.913843 172.230414-2.6911 64.222743 21.601534 126.627175 66.913843 172.230414 43.566731 43.421266 102.989133 67.132041 164.448043 65.750125 71.568719 0.800057 139.573549-31.056751 184.740394-86.47887l53.240145 53.240145c-27.856524 33.311457-62.840827 59.931529-102.334541 77.969174-42.621209 19.783223-89.097237 29.674835-136.00966 28.947511zM5151.644437 813.221394h-76.514526V216.379004H5151.644437v596.84239zM5276.598766 453.99588c83.424107-82.842247 218.124583-82.842247 301.548689 0 39.566446 41.821152 60.877051 97.679665 59.131473 155.211024 1.745579 57.531359-19.565026 113.389871-59.131473 155.211023-83.424107 82.842247-218.124583 82.842247-301.548689 0-39.566446-41.821152-60.877051-97.679665-59.131473-155.211023-1.745579-57.531359 19.492293-113.389871 59.131473-155.211024zM5333.475533 716.414518c48.948931 51.712764 130.554727 53.967469 182.340223 5.018538 1.745579-1.600114 3.418425-3.345692 5.018538-5.018538 26.983735-28.94751 41.239293-67.568435 39.566446-107.134882 1.745579-39.566446-12.509979-78.187371-39.566446-107.134881-48.948931-51.712764-130.554727-53.967469-182.340223-5.018539-1.745579 1.600114-3.418425 3.345692-5.018538 5.018539-26.983735 28.94751-41.239293 67.568435-39.566447 107.134881-1.527381 39.493714 12.873642 77.969174 39.930109 106.77122l-0.363662 0.363662zM6061.090846 813.221394h-73.896157v-56.513105h-2.181973c-13.164571 21.456069-31.784076 39.057319-53.96747 50.985439-22.983451 13.310036-49.167128 20.365083-75.787201 20.292351-43.784928 2.98203-86.478869-14.182825-116.008239-46.548761-28.001989-35.420697-42.039349-79.860217-39.566446-124.881597V405.265147h76.514525v237.253214c0 76.150863 33.602387 114.189928 100.879892 114.189928 30.329427 0.945522 59.204205-12.800909 77.605512-36.948079 19.855956-25.092691 30.402159-56.294907 29.965764-88.29718v-226.197883h76.514526v407.956247zM6320.891116 826.53143c-52.512821 0.145465-102.480006-22.619788-136.736984-62.477165-38.329995-42.330279-58.840543-97.752397-57.313162-154.847361-1.527381-57.094964 18.983166-112.517082 57.313162-154.847361 34.256978-39.784644 84.224164-62.622629 136.736984-62.477165 29.092975-0.436395 57.822289 6.400455 83.496839 19.928688 22.619788 11.34626 41.74842 28.583848 55.422118 49.894453h3.345692l-3.345692-56.513105V216.379004h76.514526v596.84239h-73.896158v-56.513105h-3.345692c-13.673698 21.310604-32.80233 38.548192-55.422118 49.894453-25.456353 13.382769-53.894737 20.29235-82.769515 19.928688z m12.582712-69.823141c34.984303 0.509127 68.513957-14.037361 92.006534-39.930109 25.965481-29.602102 39.275517-68.223027 36.948079-107.571276 2.327438-39.275517-10.982598-77.969174-36.948079-107.571276-46.403296-51.058172-125.390724-54.767526-176.448895-8.291498-2.909298 2.618368-5.67313 5.454933-8.291498 8.291498-26.038213 29.383905-39.348249 67.932097-36.948079 107.134881-2.40017 39.202784 10.909866 77.750977 36.948079 107.134882 23.56531 26.474608 57.385894 41.312025 92.733859 40.802898z" fill="#5F6368" p-id="4324"></path></svg>
\ No newline at end of file
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index b6563203d5..ad49c53a3f 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -499,6 +499,7 @@ The above is the content you need to summarize.`,
upgrade: 'Upgrade',
addLlmTitle: 'Add LLM',
modelName: 'Model name',
+ modelID: 'Model ID',
modelUid: 'Model UID',
modelNameMessage: 'Please input your model name!',
modelType: 'Model type',
@@ -551,6 +552,15 @@ The above is the content you need to summarize.`,
addFishAudioRefID: 'FishAudio Refrence ID',
addFishAudioRefIDMessage:
'Please input the Reference ID (leave blank to use the default model).',
+ GoogleModelIDMessage: 'Please input your model ID!',
+ addGoogleProjectID: 'Project ID',
+ GoogleProjectIDMessage: 'Please input your Project ID',
+ addGoogleServiceAccountKey:
+ 'Service Account Key(Leave blank if you use Application Default Credentials)',
+ GoogleServiceAccountKeyMessage:
+ 'Please input Google Cloud Service Account Key in base64 format',
+ addGoogleRegion: 'Google Cloud Region',
+ GoogleRegionMessage: 'Please input Google Cloud Region',
},
message: {
registered: 'Registered!',
diff --git a/web/src/locales/zh-traditional.ts b/web/src/locales/zh-traditional.ts
index 01eebf4244..dc793d9057 100644
--- a/web/src/locales/zh-traditional.ts
+++ b/web/src/locales/zh-traditional.ts
@@ -461,6 +461,7 @@ export default {
upgrade: '升級',
addLlmTitle: '添加Llm',
modelName: '模型名稱',
+ modelID: '模型ID',
modelUid: '模型uid',
modelType: '模型類型',
addLlmBaseUrl: '基礎 Url',
@@ -511,6 +512,15 @@ export default {
addFishAudioAKMessage: '請輸入 API KEY',
addFishAudioRefID: 'FishAudio Refrence ID',
addFishAudioRefIDMessage: '請輸入引用模型的ID(留空表示使用默認模型)',
+ GoogleModelIDMessage: '請輸入 model ID!',
+ addGoogleProjectID: 'Project ID',
+ GoogleProjectIDMessage: '請輸入 Project ID',
+ addGoogleServiceAccountKey:
+ 'Service Account Key(Leave blank if you use Application Default Credentials)',
+ GoogleServiceAccountKeyMessage:
+ '請輸入 Google Cloud Service Account Key in base64 format',
+ addGoogleRegion: 'Google Cloud 區域',
+ GoogleRegionMessage: '請輸入 Google Cloud 區域',
},
message: {
registered: '註冊成功',
diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts
index c82623082d..c7b6ea2ce1 100644
--- a/web/src/locales/zh.ts
+++ b/web/src/locales/zh.ts
@@ -478,6 +478,7 @@ export default {
upgrade: '升级',
addLlmTitle: '添加 LLM',
modelName: '模型名称',
+ modelID: '模型ID',
modelUid: '模型UID',
modelType: '模型类型',
addLlmBaseUrl: '基础 Url',
@@ -528,6 +529,15 @@ export default {
FishAudioAKMessage: '请输入 API KEY',
addFishAudioRefID: 'FishAudio Refrence ID',
FishAudioRefIDMessage: '请输入引用模型的ID(留空表示使用默认模型)',
+ GoogleModelIDMessage: '请输入 model ID!',
+ addGoogleProjectID: 'Project ID',
+ GoogleProjectIDMessage: '请输入 Project ID',
+ addGoogleServiceAccountKey:
+ 'Service Account Key(Leave blank if you use Application Default Credentials)',
+ GoogleServiceAccountKeyMessage:
+ '请输入 Google Cloud Service Account Key in base64 format',
+ addGoogleRegion: 'Google Cloud 区域',
+ GoogleRegionMessage: '请输入 Google Cloud 区域',
},
message: {
registered: '注册成功',
diff --git a/web/src/pages/user-setting/setting-model/constant.ts b/web/src/pages/user-setting/setting-model/constant.ts
index a644c21c86..8ac93e7824 100644
--- a/web/src/pages/user-setting/setting-model/constant.ts
+++ b/web/src/pages/user-setting/setting-model/constant.ts
@@ -39,6 +39,7 @@ export const IconMap = {
'Tencent Cloud': 'tencent-cloud',
Anthropic: 'anthropic',
'Voyage AI': 'voyage',
+ 'Google Cloud': 'google-cloud',
};
export const BedrockRegionList = [
diff --git a/web/src/pages/user-setting/setting-model/google-modal/index.tsx b/web/src/pages/user-setting/setting-model/google-modal/index.tsx
new file mode 100644
index 0000000000..d1d17c5811
--- /dev/null
+++ b/web/src/pages/user-setting/setting-model/google-modal/index.tsx
@@ -0,0 +1,95 @@
+import { useTranslate } from '@/hooks/common-hooks';
+import { IModalProps } from '@/interfaces/common';
+import { IAddLlmRequestBody } from '@/interfaces/request/llm';
+import { Form, Input, Modal, Select } from 'antd';
+
+type FieldType = IAddLlmRequestBody & {
+ google_project_id: string;
+ google_region: string;
+ google_service_account_key: string;
+};
+
+const { Option } = Select;
+
+const GoogleModal = ({
+ visible,
+ hideModal,
+ onOk,
+ loading,
+ llmFactory,
+}: IModalProps<IAddLlmRequestBody> & { llmFactory: string }) => {
+ const [form] = Form.useForm<FieldType>();
+
+ const { t } = useTranslate('setting');
+ const handleOk = async () => {
+ const values = await form.validateFields();
+
+ const data = {
+ ...values,
+ llm_factory: llmFactory,
+ };
+
+ onOk?.(data);
+ };
+
+ return (
+ <Modal
+ title={t('addLlmTitle', { name: llmFactory })}
+ open={visible}
+ onOk={handleOk}
+ onCancel={hideModal}
+ okButtonProps={{ loading }}
+ >
+ <Form
+ name="basic"
+ style={{ maxWidth: 600 }}
+ autoComplete="off"
+ layout={'vertical'}
+ form={form}
+ >
+ <Form.Item<FieldType>
+ label={t('modelType')}
+ name="model_type"
+ initialValue={'chat'}
+ rules={[{ required: true, message: t('modelTypeMessage') }]}
+ >
+ <Select placeholder={t('modelTypeMessage')}>
+ <Option value="chat">chat</Option>
+ </Select>
+ </Form.Item>
+ <Form.Item<FieldType>
+ label={t('modelID')}
+ name="llm_name"
+ rules={[{ required: true, message: t('GoogleModelIDMessage') }]}
+ >
+ <Input placeholder={t('GoogleModelIDMessage')} />
+ </Form.Item>
+ <Form.Item<FieldType>
+ label={t('addGoogleProjectID')}
+ name="google_project_id"
+ rules={[{ required: true, message: t('GoogleProjectIDMessage') }]}
+ >
+ <Input placeholder={t('GoogleProjectIDMessage')} />
+ </Form.Item>
+ <Form.Item<FieldType>
+ label={t('addGoogleRegion')}
+ name="google_region"
+ rules={[{ required: true, message: t('GoogleRegionMessage') }]}
+ >
+ <Input placeholder={t('GoogleRegionMessage')} />
+ </Form.Item>
+ <Form.Item<FieldType>
+ label={t('addGoogleServiceAccountKey')}
+ name="google_service_account_key"
+ rules={[
+ { required: true, message: t('GoogleServiceAccountKeyMessage') },
+ ]}
+ >
+ <Input placeholder={t('GoogleServiceAccountKeyMessage')} />
+ </Form.Item>
+ </Form>
+ </Modal>
+ );
+};
+
+export default GoogleModal;
diff --git a/web/src/pages/user-setting/setting-model/hooks.ts b/web/src/pages/user-setting/setting-model/hooks.ts
index 1c60bbcef3..f076a27d15 100644
--- a/web/src/pages/user-setting/setting-model/hooks.ts
+++ b/web/src/pages/user-setting/setting-model/hooks.ts
@@ -298,6 +298,33 @@ export const useSubmitFishAudio = () => {
};
};
+export const useSubmitGoogle = () => {
+ const { addLlm, loading } = useAddLlm();
+ const {
+ visible: GoogleAddingVisible,
+ hideModal: hideGoogleAddingModal,
+ showModal: showGoogleAddingModal,
+ } = useSetModalState();
+
+ const onGoogleAddingOk = useCallback(
+ async (payload: IAddLlmRequestBody) => {
+ const ret = await addLlm(payload);
+ if (ret === 0) {
+ hideGoogleAddingModal();
+ }
+ },
+ [hideGoogleAddingModal, addLlm],
+ );
+
+ return {
+ GoogleAddingLoading: loading,
+ onGoogleAddingOk,
+ GoogleAddingVisible,
+ hideGoogleAddingModal,
+ showGoogleAddingModal,
+ };
+};
+
export const useSubmitBedrock = () => {
const { addLlm, loading } = useAddLlm();
const {
diff --git a/web/src/pages/user-setting/setting-model/index.tsx b/web/src/pages/user-setting/setting-model/index.tsx
index 235ee66e3f..c4a2a1cef4 100644
--- a/web/src/pages/user-setting/setting-model/index.tsx
+++ b/web/src/pages/user-setting/setting-model/index.tsx
@@ -32,11 +32,13 @@ import ApiKeyModal from './api-key-modal';
import BedrockModal from './bedrock-modal';
import { IconMap } from './constant';
import FishAudioModal from './fish-audio-modal';
+import GoogleModal from './google-modal';
import {
useHandleDeleteLlm,
useSubmitApiKey,
useSubmitBedrock,
useSubmitFishAudio,
+ useSubmitGoogle,
useSubmitHunyuan,
useSubmitOllama,
useSubmitSpark,
@@ -104,7 +106,8 @@ const ModelCard = ({ item, clickApiKey }: IModelCardProps) => {
item.name === 'XunFei Spark' ||
item.name === 'BaiduYiyan' ||
item.name === 'Fish Audio' ||
- item.name === 'Tencent Cloud'
+ item.name === 'Tencent Cloud' ||
+ item.name === 'Google Cloud'
? t('addTheModel')
: 'API-Key'}
<SettingOutlined />
@@ -186,6 +189,14 @@ const UserSettingModel = () => {
HunyuanAddingLoading,
} = useSubmitHunyuan();
+ const {
+ GoogleAddingVisible,
+ hideGoogleAddingModal,
+ showGoogleAddingModal,
+ onGoogleAddingOk,
+ GoogleAddingLoading,
+ } = useSubmitGoogle();
+
const {
TencentCloudAddingVisible,
hideTencentCloudAddingModal,
@@ -235,6 +246,7 @@ const UserSettingModel = () => {
BaiduYiyan: showyiyanAddingModal,
'Fish Audio': showFishAudioAddingModal,
'Tencent Cloud': showTencentCloudAddingModal,
+ 'Google Cloud': showGoogleAddingModal,
}),
[
showBedrockAddingModal,
@@ -244,6 +256,7 @@ const UserSettingModel = () => {
showSparkAddingModal,
showyiyanAddingModal,
showFishAudioAddingModal,
+ showGoogleAddingModal,
],
);
@@ -364,6 +377,13 @@ const UserSettingModel = () => {
loading={HunyuanAddingLoading}
llmFactory={'Tencent Hunyuan'}
></HunyuanModal>
+ <GoogleModal
+ visible={GoogleAddingVisible}
+ hideModal={hideGoogleAddingModal}
+ onOk={onGoogleAddingOk}
+ loading={GoogleAddingLoading}
+ llmFactory={'Google Cloud'}
+ ></GoogleModal>
<TencentCloudModal
visible={TencentCloudAddingVisible}
hideModal={hideTencentCloudAddingModal}