Skip to content

Commit

Permalink
Some fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosmo committed Apr 5, 2024
1 parent 3befd82 commit 1b365ea
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/gemini-pro-slack-bot/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module "function" {
slack_token = var.slack_token
slack_app_id = var.slack_app_id
vertex_region = var.vertex_region
vertex_model = var.vertex_model
vertex_model = var.vertex_search.enabled == false ? var.vertex_model : var.vertex_model_multimodal
api_enabled = false
}, var.vertex_search.enabled == true ? {
api_enabled = true
Expand Down
9 changes: 6 additions & 3 deletions examples/gemini-pro-slack-bot/slack-bot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ pipeline:
messages: slack_thread
%{ if api_enabled ~}
prompt: |
Do not consult external sources unless my question is strictly related to Alphabet financials which
you don't know the answer for.
Do not call functions unless my question is strictly related to Alphabet financials which
you don't know the answer for. Answer questions without calling functions if you know the
answer well enough.
%{ endif ~}

Expand All @@ -124,6 +125,7 @@ pipeline:
{% if slack_should_reply %}1{% endif %}
output: vertex_response
config:
apiVersion: "v1beta"
location: "${vertex_region}"
modelId: "${vertex_model}"
method: "streamGenerateContent"
Expand All @@ -147,7 +149,8 @@ pipeline:
functionDeclarations:
- name: search_vertex
description: |
Current information on Alphabet financials.
This function is only for getting current information on Alphabet
financials, do not use it for anything else.
parameters:
type: object
properties:
Expand Down
8 changes: 7 additions & 1 deletion examples/gemini-pro-slack-bot/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ variable "vertex_region" {
variable "vertex_model" {
description = "Vertex AI model to use"
type = string
default = "gemini-1.0-pro"
}

variable "vertex_model_multimodal" {
description = "Vertex AI multimodal model to use"
type = string
default = "gemini-1.0-pro-vision"
}

Expand Down Expand Up @@ -68,4 +74,4 @@ variable "vertex_search" {
location = optional(string)
datastore_id = optional(string)
})
}
}
8 changes: 6 additions & 2 deletions examples/gemini-pro-slack-bot/vertex-search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# It can be also run interactively as a non-Pub/Sub function by specifying
# WEBSERVER=1 environment parameter (or --webserver flag).
#
# Example:

pipeline:
- type: processor.genericjson
Expand Down Expand Up @@ -52,6 +51,8 @@ pipeline:
# preamble: "Custom prompt preamble"
modelSpec:
version: "stable"
extractiveContentSpec:
maxExtractiveAnswerCount: 1

# Log the response
- type: output.logger
Expand All @@ -65,4 +66,7 @@ pipeline:
headers:
content-type: "application/json"
body: |
{{ vertex_response|json_encode }}
{%- set resp = [] -%}
{%- for result in vertex_response.results -%}
{%- endfor -%}
13 changes: 8 additions & 5 deletions processors/vertexai.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class VertexaiProcessor(Processor):
datastoreId (str): Data store ID (either this or engineId).
servingConfig (str, optional): Serving configuration (defaults to "default_config").
returnErrors (bool, optional): Set to true to return errors
apiVersion (str, optional): API version, defaults to "v1".
request (dict): Request.
"""

Expand Down Expand Up @@ -70,17 +71,19 @@ def process(self, output_var='vertexai'):
self.config['servingConfig'], 'serving_config'
) if 'servingConfig' in self.config else 'default_config'

api_version = self._jinja_expand_string(self.config['apiVersion']) if 'apiVersion' in self.config else 'v1'

method = self._jinja_expand_string(
self.config['method'],
'method') if 'method' in self.config else 'search'
if mode == 'search':
if engine_id:
api_path = 'https://%s-discoveryengine.googleapis.com/v1/projects/%s/locations/%s/collections/%s/engineId/%s/servingConfigs/%s:%s' % (
location, project, location, collection, engine_id,
api_path = 'https://%s-discoveryengine.googleapis.com/%s/projects/%s/locations/%s/collections/%s/engineId/%s/servingConfigs/%s:%s' % (
api_version, location, project, location, collection, engine_id,
serving_config, method)
else:
api_path = 'https://%s-discoveryengine.googleapis.com/v1/projects/%s/locations/%s/collections/%s/dataStores/%s/servingConfigs/%s:%s' % (
location, project, location, collection, datastore_id,
api_path = 'https://%s-discoveryengine.googleapis.com/%s/projects/%s/locations/%s/collections/%s/dataStores/%s/servingConfigs/%s:%s' % (
location, api_version, project, location, collection, datastore_id,
serving_config, method)

return_errors = False
Expand Down Expand Up @@ -123,7 +126,7 @@ def process(self, output_var='vertexai'):
self.logger.error('Error calling %s: %s' % (e.request.url, e),
extra={'response': e.response.text})
raise e
print(response.content)

response_json = response.json()
return {
output_var: response_json,
Expand Down

0 comments on commit 1b365ea

Please sign in to comment.