// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Oci.GenerativeaiinferenceService;
using Oci.Common;
using Oci.Common.Auth;
namespace Oci.Sdk.DotNet.Example.Generativeaiinference
{
public class ChatExample
{
public static async Task Main()
{
// Create a request and dependent object(s).
var chatDetails = new Oci.GenerativeaiinferenceService.Models.ChatDetails
{
CompartmentId = "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
ServingMode = new Oci.GenerativeaiinferenceService.Models.OnDemandServingMode
{
ModelId = "ocid1.test.oc1..<unique_ID>EXAMPLE-modelId-Value"
},
ChatRequest = new Oci.GenerativeaiinferenceService.Models.CohereChatRequest
{
Message = "EXAMPLE-message-Value",
ChatHistory = new List<Oci.GenerativeaiinferenceService.Models.CohereMessage>
{
new Oci.GenerativeaiinferenceService.Models.CohereSystemMessage
{
Message = "EXAMPLE-message-Value"
}
},
Documents = new List<Object>
{
"EXAMPLE-documents-Value"
},
ResponseFormat = new Oci.GenerativeaiinferenceService.Models.CohereResponseJsonFormat
{
Schema = "EXAMPLE-schema-Value"
},
IsSearchQueriesOnly = false,
PreambleOverride = "EXAMPLE-preambleOverride-Value",
IsStream = false,
StreamOptions = new Oci.GenerativeaiinferenceService.Models.StreamOptions
{
IsIncludeUsage = false
},
MaxTokens = 346,
MaxInputTokens = 519,
Temperature = 0.6024618,
TopK = 335,
TopP = 0.45686334,
PromptTruncation = Oci.GenerativeaiinferenceService.Models.CohereChatRequest.PromptTruncationEnum.Off,
FrequencyPenalty = 0.40616524,
PresencePenalty = 0.8043424,
Seed = 305,
IsEcho = true,
Tools = new List<Oci.GenerativeaiinferenceService.Models.CohereTool>
{
new Oci.GenerativeaiinferenceService.Models.CohereTool
{
Name = "EXAMPLE-name-Value",
Description = "EXAMPLE-description-Value",
ParameterDefinitions = new Dictionary<string, Oci.GenerativeaiinferenceService.Models.CohereParameterDefinition>()
{
{
"EXAMPLE_KEY_W0Y40",
new Oci.GenerativeaiinferenceService.Models.CohereParameterDefinition
{
Description = "EXAMPLE-description-Value",
Type = "EXAMPLE-type-Value",
IsRequired = false
}
}
}
}
},
ToolResults = new List<Oci.GenerativeaiinferenceService.Models.CohereToolResult>
{
new Oci.GenerativeaiinferenceService.Models.CohereToolResult
{
Call = new Oci.GenerativeaiinferenceService.Models.CohereToolCall
{
Name = "EXAMPLE-name-Value",
Parameters = "EXAMPLE-parameters-Value"
},
Outputs = new List<Object>
{
"EXAMPLE-outputs-Value"
}
}
},
IsForceSingleStep = false,
StopSequences = new List<string>
{
"EXAMPLE--Value"
},
IsRawPrompting = false,
CitationQuality = Oci.GenerativeaiinferenceService.Models.CohereChatRequest.CitationQualityEnum.Accurate,
SafetyMode = Oci.GenerativeaiinferenceService.Models.CohereChatRequest.SafetyModeEnum.Contextual
}
};
var chatRequest = new Oci.GenerativeaiinferenceService.Requests.ChatRequest
{
ChatDetails = chatDetails,
OpcRetryToken = "EXAMPLE-opcRetryToken-Value",
OpcRequestId = "AF3TIJYGONJZU1OGWPHN<unique_ID>"
};
// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.
var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT");
try
{
// Create a service client and send the request.
using (var client = new GenerativeAiInferenceClient(provider, new ClientConfiguration()))
{
var response = await client.Chat(chatRequest);
// Retrieve value from the response.
var modelIdValue = response.ChatResult.ModelId;
}
}
catch (Exception e)
{
Console.WriteLine($"Chat Failed with {e.Message}");
throw e;
}
}
}
}