-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
review: rename and move files and other fixes
- Loading branch information
Showing
14 changed files
with
170 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
|
||
namespace OpenAI; | ||
|
||
internal static class AppContextSwitchHelper | ||
{ | ||
/// <summary> | ||
/// Determines if either an AppContext switch or its corresponding Environment Variable is set | ||
/// </summary> | ||
/// <param name="appContexSwitchName">Name of the AppContext switch.</param> | ||
/// <param name="environmentVariableName">Name of the Environment variable.</param> | ||
/// <returns>If the AppContext switch has been set, returns the value of the switch. | ||
/// If the AppContext switch has not been set, returns the value of the environment variable. | ||
/// False if neither is set. | ||
/// </returns> | ||
public static bool GetConfigValue(string appContexSwitchName, string environmentVariableName) | ||
{ | ||
// First check for the AppContext switch, giving it priority over the environment variable. | ||
if (AppContext.TryGetSwitch(appContexSwitchName, out bool value)) | ||
{ | ||
return value; | ||
} | ||
// AppContext switch wasn't used. Check the environment variable. | ||
string envVar = Environment.GetEnvironmentVariable(environmentVariableName); | ||
if (envVar != null && (envVar.Equals("true", StringComparison.OrdinalIgnoreCase) || envVar.Equals("1"))) | ||
{ | ||
return true; | ||
} | ||
|
||
// Default to false. | ||
return false; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
src/Utility/Instrumentation/Constants.cs → ...ility/Telemetry/OpenTelemetryConstants.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using OpenAI.Chat; | ||
using System; | ||
|
||
namespace OpenAI.Telemetry; | ||
|
||
internal class OpenTelemetrySource | ||
{ | ||
private const string ChatOperationName = "chat"; | ||
private readonly bool IsOTelEnabled = AppContextSwitchHelper | ||
.GetConfigValue("OpenAI.Experimental.EnableOpenTelemetry", "OPENAI_EXPERIMENTAL_ENABLE_OPEN_TELEMETRY"); | ||
|
||
private readonly string _serverAddress; | ||
private readonly int _serverPort; | ||
private readonly string _model; | ||
|
||
public OpenTelemetrySource(string model, Uri endpoint) | ||
{ | ||
_serverAddress = endpoint.Host; | ||
_serverPort = endpoint.Port; | ||
_model = model; | ||
} | ||
|
||
public OpenTelemetryScope StartChatScope(ChatCompletionOptions completionsOptions) | ||
{ | ||
return IsOTelEnabled | ||
? OpenTelemetryScope.StartChat(_model, ChatOperationName, _serverAddress, _serverPort, completionsOptions) | ||
: null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.