-;i6 UddlmZddlZddlmZddlZddlmZmZmZm Z m Z ddl m Z ddl mcmZddlmZddlmZmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZdZejj Z ee!e"e fZ#ie j$e j$de j$de j$de j$e j%e j%de j%de j%de j%e j&e j&de j&de j&de j&e j'e j'de j'de j'de j'Z(de)d<dEd Z*eej+e,e"ej-fej-ffZ.eej/ee.e e"ej-ffZ0dFd$Z1ee"ej2ej2ej3ej3fZ4Gd%d&e Z5ee4e5ej6fZ7dGd(Z8dHd-Z9edddddd.dId=Z:edddddddd>dJdCZ;edddddddd>dJdDZRsa&&233 fh ' '  \swx~sstI \ \ \   H&'"" V$$WW4 dF3 4 4 W OOD ! ! ! ! e $ $ WKB OO2-2J72S2STT U U U U OO3q66m6Nt6T6TUU V V V V  #X 6 6 66r*cBeZdZUded<ded<ded<ded<d ed <d S) SemanticRetrieverConfigDictSourceNameTyper+content_types.ContentsTypequeryz"Optional[Iterable[MetadataFilter]]metadata_filterz Optional[int]max_chunks_countzOptional[float]minimum_relevance_scoreN)r5 __module__ __qualname____annotations__r*r(r@r@zsN%%%%7777####,,,,,,r*r@ str | Nonect|tr|St|tjtjtjtjfr|jSdSr$)r%r&rCorpusr Documentname)r+s r(_maybe_get_source_namerPsT&# '8PRXRab  {tr*SemanticRetrieverConfigOptionsrCrBprotos.SemanticRetrieverConfigct|tjr|St|}|d|i}nUt|trt|d|d<n't dt |jd||d||d<n8t|dtrtj |d|d<tj|S)Nr+zlInvalid input: Failed to create a 'protos.SemanticRetrieverConfig' from the provided source. Received type: z, Received value: rC) r%r SemanticRetrieverConfigrPdictr3r4r5r&rr;)r+rCrOs r(_make_semantic_retriever_configrVs&&899 !& ) )D D! FD ! ! 1&2BCCx ("6ll3 ( (% ( (   gw F7OS ) )D'26'?CCw  )& 1 11r*)modelinline_passagessemantic_retriever answer_stylesafety_settings temperaturerWmodel_types.AnyModelNameOptionscontentsrXGroundingPassagesOptions | NonerY%SemanticRetrieverConfigOptions | NonerZAnswerStyle | Noner[(safety_types.SafetySettingOptions | Noner\ float | Noneprotos.GenerateAnswerRequestc tj|}tj|}|rt j|}||t d|d|d|t|}n/|t||d}ntd|d|d|rt|}tj |||||||S)a constructs a protos.GenerateAnswerRequest object by organizing the input parameters for the API call to generate a grounded answer from the model. Args: model: Name of the model used to generate the grounded response. contents: Content of the current conversation with the model. For single-turn query, this is a single question to answer. For multi-turn queries, this is a repeated field that contains conversation history and the last `Content` in the list containing the question. inline_passages: Grounding passages (a list of `Content`-like objects or `(id, content)` pairs, or a `protos.GroundingPassages`) to send inline with the request. Exclusive with `semantic_retriever`, one must be set, but not both. semantic_retriever: A Corpus, Document, or `protos.SemanticRetrieverConfig` to use for grounding. Exclusive with `inline_passages`, one must be set, but not both. answer_style: Style for grounded answers. safety_settings: Safety settings for generated output. temperature: The temperature for randomness in the output. Returns: Call for protos.GenerateAnswerRequest(). NzInvalid configuration: Please set either 'inline_passages' or 'semantic_retriever_config', but not both. Received for inline_passages: z, and for semantic_retriever: .zInvalid configuration: Either 'inline_passages' or 'semantic_retriever_config' must be provided, but currently both are 'None'. Received for inline_passages: rWr^rXrYr[r\rZ) r make_model_namer to_contentsrnormalize_safety_settings ValueErrorr>rVr3r)r GenerateAnswerRequest)rWr^rXrYrZr[r\s r(_make_generate_answer_requestrns?<  ' . .E(22HR&@QQ"'9'E r-< r r\n r r r     $2?CC  '<=OQYZ\Q]^^ r-< r r\n r r r   5&|44  ''-'!   r*)rWrXrYrZr[r\clientrequest_optionsro"glm.GenerativeServiceClient | Nonerp&helper_types.RequestOptionsType | Nonec v|i}|t}t|||||||} |j| fi|} | S)aCalls the GenerateAnswer API and returns a `types.Answer` containing the response. You can pass a literal list of text chunks: >>> from google.generativeai import answer >>> answer.generate_answer( ... content=question, ... inline_passages=splitter.split(document) ... ) Or pass a reference to a retreiver Document or Corpus: >>> from google.generativeai import answer >>> from google.generativeai import retriever >>> my_corpus = retriever.get_corpus('my_corpus') >>> genai.generate_answer( ... content=question, ... semantic_retriever=my_corpus ... ) Args: model: Which model to call, as a string or a `types.Model`. contents: The question to be answered by the model, grounded in the provided source. inline_passages: Grounding passages (a list of `Content`-like objects or (id, content) pairs, or a `protos.GroundingPassages`) to send inline with the request. Exclusive with `semantic_retriever`, one must be set, but not both. semantic_retriever: A Corpus, Document, or `protos.SemanticRetrieverConfig` to use for grounding. Exclusive with `inline_passages`, one must be set, but not both. answer_style: Style in which the grounded answer should be returned. safety_settings: Safety settings for generated output. Defaults to None. temperature: Controls the randomness of the output. client: If you're not relying on a default client, you pass a `glm.GenerativeServiceClient` instead. request_options: Options for the request. Returns: A `types.Answer` containing the model's text answer response. Nrh)r rngenerate_answer rWr^rXrYrZr[r\rorprequestresponses r(rtrtsjf ~.00+'-'!G&v%gAAAAH Or*c K|i}|t}t|||||||} |j| fi|d{V} | S)a^ Calls the API and returns a `types.Answer` containing the answer. Args: model: Which model to call, as a string or a `types.Model`. contents: The question to be answered by the model, grounded in the provided source. inline_passages: Grounding passages (a list of `Content`-like objects or (id, content) pairs, or a `protos.GroundingPassages`) to send inline with the request. Exclusive with `semantic_retriever`, one must be set, but not both. semantic_retriever: A Corpus, Document, or `protos.SemanticRetrieverConfig` to use for grounding. Exclusive with `inline_passages`, one must be set, but not both. answer_style: Style in which the grounded answer should be returned. safety_settings: Safety settings for generated output. Defaults to None. temperature: Controls the randomness of the output. client: If you're not relying on a default client, you pass a `glm.GenerativeServiceClient` instead. Returns: A `types.Answer` containing the model's text answer response. Nrh)r rnrtrus r(generate_answer_asyncry9s@ ~466+'-'!G,V+GGGGGGGGGGGH Or*)rr r!r")r+r,r!r-)r!rK)r+rQrCrBr!rR)rWr]r^rBrXr_rYr`rZrar[rbr\rcr!rd)rWr]r^rBrXr_rYr`rZrar[rbr\rcrorqrprr)= __future__r dataclassescollections.abcr itertoolstypingrrrrtyping_extensionsr google.ai.generativelanguageaigenerativelanguageglmgoogle.generativeair google.generativeai.clientr r google.generativeai.typesr rrrr)google.generativeai.types.retriever_typesrDEFAULT_ANSWER_MODELrmr"intr&r ANSWER_STYLE_UNSPECIFIED ABSTRACTIVE EXTRACTIVEVERBOSErrIr)r8r: ContentTypeGroundingPassageOptionsr2r,r>rMrNrAr@rTrQrPrVrnrtryrJr*r(rsO#""""""$$$$$$::::::::::::::''''''*********&&&&&&211111222222222222333333555555DDDDDD#*6 3[019(+*N9{+9 D9;7 9 [4 9 { 9 79;*9K29{9{59+(9,9{9K/9 {"!9( sM,E'E!F Haa !  $% C* *+- 7 7 7 7F 0H&/Y -----)---"' "$"2222:.B7;@D'+@D $??????H.B7;@D'+@D $15>BEEEEEET.B7;@D'+@D $15>B22222222r*