Skip to content

Commit

Permalink
Touchups for pr tool calling
Browse files Browse the repository at this point in the history
* branch naming convention
* hallucination minimization
  • Loading branch information
michaeljguarino committed Dec 4, 2024
1 parent 745dd94 commit fe6d025
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 96 deletions.
59 changes: 28 additions & 31 deletions assets/src/components/ai/chatbot/AISuggestFix.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Button, Markdown, PrOpenIcon, Toast } from '@pluralsh/design-system'
import {
Button,
LinkoutIcon,
Markdown,
PrOpenIcon,
Toast,
} from '@pluralsh/design-system'
import {
Dispatch,
ReactNode,
Expand All @@ -8,7 +14,6 @@ import {
useRef,
useState,
} from 'react'
import { useTheme } from 'styled-components'
import {
AiDelta,
AiInsightFragment,
Expand Down Expand Up @@ -87,37 +92,15 @@ function FixPr({
const [mutation, { data, loading, error }] = useAiFixPrMutation({
variables: { insightId, messages: [{ role: AiRole.User, content: fix }] },
})
const theme = useTheme()

// TEMP FIX, implement permanent solution in DS
const successToastRef = useRef<HTMLDivElement>(null)
const errorToastRef = useRef<HTMLDivElement>(null)
useEffect(() => {
if (successToastRef.current) successToastRef.current.style.zIndex = '10000'
if (errorToastRef.current) errorToastRef.current.style.zIndex = '10000'
}, [data?.aiFixPr])

return (
<>
{data?.aiFixPr && (
<Toast
ref={successToastRef}
severity="info"
position="top-right"
margin="large"
heading="PR Created!"
>
<a
href={data?.aiFixPr?.url}
target="_blank"
rel="noreferrer"
style={{ textDecoration: 'none', cursor: 'pointer' }}
color={theme.colors['action-link-inline']}
>
{data?.aiFixPr?.url}
</a>
</Toast>
)}
{error && (
<Toast
ref={errorToastRef}
Expand All @@ -129,13 +112,27 @@ function FixPr({
{error.message}
</Toast>
)}
<Button
startIcon={<PrOpenIcon />}
onClick={mutation}
loading={loading}
>
Open PR
</Button>
{data?.aiFixPr ? (
<Button
primary
type="button"
endIcon={<LinkoutIcon />}
as="a"
href={data?.aiFixPr?.url}
target="_blank"
rel="noopener noreferrer"
>
View PR
</Button>
) : (
<Button
startIcon={<PrOpenIcon />}
onClick={mutation}
loading={loading}
>
Create PR
</Button>
)}
</>
)
}
Expand Down
25 changes: 25 additions & 0 deletions assets/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,15 @@ export type AnthropicSettings = {
__typename?: 'AnthropicSettings';
/** the anthropic model version to use */
model?: Maybe<Scalars['String']['output']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: Maybe<Scalars['String']['output']>;
};

export type AnthropicSettingsAttributes = {
accessToken?: InputMaybe<Scalars['String']['input']>;
model?: InputMaybe<Scalars['String']['input']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: InputMaybe<Scalars['String']['input']>;
};

/** a representation of a kubernetes api deprecation */
Expand Down Expand Up @@ -635,6 +639,8 @@ export type AzureOpenaiAttributes = {
endpoint: Scalars['String']['input'];
/** the exact model you wish to use */
model?: InputMaybe<Scalars['String']['input']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: InputMaybe<Scalars['String']['input']>;
};

/** Settings for configuring against Azure OpenAI */
Expand All @@ -644,6 +650,9 @@ export type AzureOpenaiSettings = {
apiVersion?: Maybe<Scalars['String']['output']>;
/** the endpoint of your azure openai version, should look like: https://{endpoint}/openai/deployments/{deployment-id} */
endpoint: Scalars['String']['output'];
model?: Maybe<Scalars['String']['output']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: Maybe<Scalars['String']['output']>;
};

export type AzureSettingsAttributes = {
Expand Down Expand Up @@ -689,6 +698,8 @@ export type BedrockAiAttributes = {
modelId: Scalars['String']['input'];
/** aws secret access key to use, you can also use IRSA for self-hosted consoles */
secretAccessKey?: InputMaybe<Scalars['String']['input']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModelId?: InputMaybe<Scalars['String']['input']>;
};

/** Settings for usage of AWS Bedrock for LLMs */
Expand All @@ -698,6 +709,8 @@ export type BedrockAiSettings = {
accessKeyId?: Maybe<Scalars['String']['output']>;
/** the bedrock model to use */
modelId: Scalars['String']['output'];
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModelId?: Maybe<Scalars['String']['output']>;
};

export type BindingAttributes = {
Expand Down Expand Up @@ -3879,13 +3892,17 @@ export type OllamaAttributes = {
/** An http authorization header to use on calls to the Ollama api */
authorization?: InputMaybe<Scalars['String']['input']>;
model: Scalars['String']['input'];
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: InputMaybe<Scalars['String']['input']>;
url: Scalars['String']['input'];
};

/** Settings for a self-hosted ollama-based LLM deployment */
export type OllamaSettings = {
__typename?: 'OllamaSettings';
model: Scalars['String']['output'];
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: Maybe<Scalars['String']['output']>;
/** the url your ollama deployment is hosted on */
url: Scalars['String']['output'];
};
Expand All @@ -3897,12 +3914,16 @@ export type OpenaiSettings = {
baseUrl?: Maybe<Scalars['String']['output']>;
/** the openai model version to use */
model?: Maybe<Scalars['String']['output']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: Maybe<Scalars['String']['output']>;
};

export type OpenaiSettingsAttributes = {
accessToken?: InputMaybe<Scalars['String']['input']>;
baseUrl?: InputMaybe<Scalars['String']['input']>;
model?: InputMaybe<Scalars['String']['input']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: InputMaybe<Scalars['String']['input']>;
};

export enum Operation {
Expand Down Expand Up @@ -9364,6 +9385,8 @@ export type VertexAiAttributes = {
project: Scalars['String']['input'];
/** optional service account json to auth to the GCP vertex apis */
serviceAccountJson?: InputMaybe<Scalars['String']['input']>;
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: InputMaybe<Scalars['String']['input']>;
};

/** Settings for usage of GCP VertexAI for LLMs */
Expand All @@ -9375,6 +9398,8 @@ export type VertexAiSettings = {
model?: Maybe<Scalars['String']['output']>;
/** the gcp project id to use */
project: Scalars['String']['output'];
/** the model to use for tool calls, which are less frequent and require more complex reasoning */
toolModel?: Maybe<Scalars['String']['output']>;
};

export type VerticalPodAutoscaler = {
Expand Down
21 changes: 16 additions & 5 deletions assets/src/helpers/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const authlessClient = new ApolloClient({
})

function maybeReconnect(socket, absintheSocket) {
console.warn('socket reconnect attempt', socket)
const chan = absintheSocket.channel
console.log('socket reconnect attempt', socket)
if (socket.connectionState() === 'closed') {
console.warn('found dead websocket, attempting a reconnect')
if (!socket.conn) {
Expand All @@ -37,12 +38,18 @@ function maybeReconnect(socket, absintheSocket) {
socket.reconnectTimer.scheduleTimeout()
}

absintheSocket.channel.rejoin()
absintheSocket.channel.rejoinTimer.scheduleTimeout()
return
}

console.warn('socket not dead, ignoring')
const state = chan.state
if (state === 'closed' || state === 'errored') {
console.log('broken absinthe channel, rejoining')
chan.rejoin()
return
}

console.log('found healthy channel', chan)
console.log('absinthe socket not dead, ignoring')
}

export function buildClient(gqlUrl, wsUrl, fetchToken) {
Expand Down Expand Up @@ -77,6 +84,10 @@ export function buildClient(gqlUrl, wsUrl, fetchToken) {
const socketLink = createAbsintheSocketLink(absintheSocket)
const gqlLink = errorLink.concat(httpLink)

absintheSocket.channel.onClose(() => {
absintheSocket.channel.rejoin()
})

const splitLink = split(
(operation) => hasSubscription(operation.query),
socketLink,
Expand Down Expand Up @@ -105,7 +116,7 @@ export function buildClient(gqlUrl, wsUrl, fetchToken) {
})

socket.onClose(() => maybeReconnect(socket, absintheSocket))
setInterval(() => maybeReconnect(socket, absintheSocket), 10000)
setInterval(() => maybeReconnect(socket, absintheSocket), 5000)

return { client, socket }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
toolModel:
description: Model to use for tool calling, which is less
frequent and often requires more advanced reasoning
type: string
required:
- tokenSecretRef
type: object
Expand Down Expand Up @@ -122,6 +126,10 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
toolModel:
description: Model to use for tool calling, which is less
frequent and often requires more advanced reasoning
type: string
required:
- endpoint
- tokenSecretRef
Expand Down Expand Up @@ -158,6 +166,10 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
toolModelId:
description: Model to use for tool calling, which is less
frequent and often requires more advanced reasoning
type: string
required:
- modelId
type: object
Expand Down Expand Up @@ -196,6 +208,10 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
toolModel:
description: Model to use for tool calling, which is less
frequent and often requires more advanced reasoning
type: string
url:
description: URL is the url this model is queryable on
type: string
Expand Down Expand Up @@ -236,6 +252,10 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
toolModel:
description: Model to use for tool calling, which is less
frequent and often requires more advanced reasoning
type: string
required:
- tokenSecretRef
type: object
Expand Down Expand Up @@ -288,6 +308,10 @@ spec:
- key
type: object
x-kubernetes-map-type: atomic
toolModel:
description: Model to use for tool calling, which is less
frequent and often requires more advanced reasoning
type: string
required:
- location
- project
Expand Down
Loading

0 comments on commit fe6d025

Please sign in to comment.