Skip to content

Commit

Permalink
Merge branch 'main' into add-github-login
Browse files Browse the repository at this point in the history
  • Loading branch information
satococoa authored Oct 31, 2024
2 parents f65cdb3 + 9813f8e commit 9cb97f6
Show file tree
Hide file tree
Showing 37 changed files with 1,834 additions and 1,287 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Giselle app
NEXT_PUBLIC_SERVICE_SITE_URL="https://example.com/"

## Enable @vercel/flags at all times in the development environment
DEBUG_FLAG="true"
UPLOAD_FILE_TO_PROMPT_NODE_FLAG="true"
VIEW_FLAG="true"
WEB_SEARCH_NODE_FLAG="true"

# @vercel/blob https://vercel.com/docs/storage/vercel-blob/using-blob-sdk
# @see https://vercel.com/docs/storage/vercel-blob/client-upload#prepare-your-local-project
BLOB_READ_WRITE_TOKEN=
Expand Down
32 changes: 28 additions & 4 deletions .github/workflows/license.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
name: License Compliance

# ## Summary
#
# This workflow runs the license_finder CLI only when it detects an update to files related to the License Finder.
# It also updates $LICENSE_REPORT and git commit.
#
# When triggered by a PR from a forked repository, $LICENSE_REPORT is not updated.
# When triggered by a push to the default branch, $LICENSE_REPORT is not updated either.

on:
push:
branches:
Expand All @@ -16,15 +24,25 @@ jobs:
env:
LICENSE_REPORT: docs/packages-license.md
steps:
- uses: actions/create-github-app-token@v1
- name: Check if running in a fork
id: fork-check
run: echo "is_fork=${{ github.event.pull_request.head.repo.fork }}" >> "$GITHUB_OUTPUT"
- name: Create GitHub App Token for non-fork PRs
uses: actions/create-github-app-token@v1
if: steps.fork-check.outputs.is_fork != 'true'
id: app-token
with:
app-id: ${{ vars.CI_TRIGGER_APP_ID }}
private-key: ${{ secrets.CI_TRIGGER_APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
- name: Checkout code for non-fork PRs
if: steps.fork-check.outputs.is_fork != 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ steps.app-token.outputs.token }}
- name: Checkout code for forked PRs
if: steps.fork-check.outputs.is_fork == 'true'
uses: actions/checkout@v4
# To make the success of this job a prerequisite for merging into the main branch,
# set a filter here instead of on: to determine whether or not to proceed to the next step.
- name: Cache dependency files
Expand Down Expand Up @@ -65,10 +83,16 @@ jobs:

# Commit the License Finder report as docs/packages-license.md
- name: Generate license report
if: steps.determine.outputs.files_changed == 'true' && github.ref_name != github.event.repository.default_branch
if: |
steps.fork-check.outputs.is_fork != 'true'
&& steps.determine.outputs.files_changed == 'true'
&& github.ref_name != github.event.repository.default_branch
run: license_finder report --format=markdown | tail -n +2 > "$LICENSE_REPORT"
- name: Commit license report and push
if: steps.determine.outputs.files_changed == 'true' && github.ref_name != github.event.repository.default_branch
if: |
steps.fork-check.outputs.is_fork != 'true'
&& steps.determine.outputs.files_changed == 'true'
&& github.ref_name != github.event.repository.default_branch
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
Expand Down
87 changes: 87 additions & 0 deletions app/(playground)/p/[agentId]/beta-proto/artifact/server-actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"use server";

import { openai } from "@ai-sdk/openai";
import { streamObject } from "ai";
import { createStreamableValue } from "ai/rsc";

import { getUserSubscriptionId, isRoute06User } from "@/app/(auth)/lib";
import { metrics } from "@opentelemetry/api";
import { Langfuse } from "langfuse";
import { schema as artifactSchema } from "../artifact/schema";
import type { SourceIndex } from "../source/types";
import { sourceIndexesToSources, sourcesToText } from "../source/utils";
import type { AgentId } from "../types";

type GenerateArtifactStreamParams = {
agentId: AgentId;
userPrompt: string;
sourceIndexes: SourceIndex[];
};
export async function generateArtifactStream(
params: GenerateArtifactStreamParams,
) {
const lf = new Langfuse();
const trace = lf.trace({
id: `giselle-${Date.now()}`,
});
const sources = await sourceIndexesToSources({
input: {
agentId: params.agentId,
sourceIndexes: params.sourceIndexes,
},
});

const system =
sources.length > 0
? `
Your primary objective is to fulfill the user's request by utilizing the information provided within the <Source> or <WebPage> tags. Analyze the structured content carefully and leverage it to generate accurate and relevant responses. Focus on addressing the user's needs effectively while maintaining coherence and context throughout the interaction.
If you use the information provided in the <WebPage>, After each piece of information, add a superscript number for citation (e.g. 1, 2, etc.).
${sourcesToText(sources)}
`
: "You generate an answer to a question. ";

const stream = createStreamableValue();

(async () => {
const model = "gpt-4o";
const generation = trace.generation({
input: params.userPrompt,
model,
});
const { partialObjectStream, object } = await streamObject({
model: openai(model),
system,
prompt: params.userPrompt,
schema: artifactSchema,
onFinish: async (result) => {
const meter = metrics.getMeter("OpenAI");
const tokenCounter = meter.createCounter("token_consumed", {
description: "Number of OpenAI API tokens consumed by each request",
});
const subscriptionId = await getUserSubscriptionId();
const isR06User = await isRoute06User();
tokenCounter.add(result.usage.totalTokens, {
subscriptionId,
isR06User,
});
generation.end({
output: result,
});
await lf.shutdownAsync();
},
});

for await (const partialObject of partialObjectStream) {
stream.update(partialObject);
}

const result = await object;

stream.done();
})();

return { object: stream.value };
}
42 changes: 42 additions & 0 deletions app/(playground)/p/[agentId]/beta-proto/connector/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { ConnectorObject } from "./types";

const v2ConnectorActionTypes = {
set: "v2.setConnectors",
} as const;
type V2ConnectorActionType =
(typeof v2ConnectorActionTypes)[keyof typeof v2ConnectorActionTypes];

interface SetConnectorsAction {
type: Extract<V2ConnectorActionType, "v2.setConnectors">;
input: SetConnectorsInput;
}
interface SetConnectorsInput {
connectors: ConnectorObject[];
}
export function setConnectors({
input,
}: { input: SetConnectorsInput }): SetConnectorsAction {
return {
type: v2ConnectorActionTypes.set,
input,
};
}
export type V2ConnectorAction = SetConnectorsAction;
export function isV2ConnectorAction(
action: unknown,
): action is V2ConnectorAction {
return Object.values(v2ConnectorActionTypes).includes(
(action as V2ConnectorAction).type,
);
}

export function v2ConnectorReducer(
connectors: ConnectorObject[],
action: V2ConnectorAction,
): ConnectorObject[] {
switch (action.type) {
case v2ConnectorActionTypes.set:
return action.input.connectors;
}
return connectors;
}
31 changes: 31 additions & 0 deletions app/(playground)/p/[agentId]/beta-proto/connector/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { GiselleNodeArchetype } from "../giselle-node/blueprints";
import type { GiselleNodeCategory, GiselleNodeId } from "../giselle-node/types";
import { createConnectorId } from "./factory";
import type { ConnectorObject } from "./types";

interface BuildConnectorArgs {
sourceNode: {
id: GiselleNodeId;
category: GiselleNodeCategory;
archetype: GiselleNodeArchetype;
};
targetNode: {
id: GiselleNodeId;
handle: string;
category: GiselleNodeCategory;
archetype: GiselleNodeArchetype;
};
}
export function buildConnector(args: BuildConnectorArgs) {
return {
id: createConnectorId(),
object: "connector",
source: args.sourceNode.id,
sourceNodeCategory: args.sourceNode.category,
sourceNodeArcheType: args.sourceNode.archetype,
target: args.targetNode.id,
targetHandle: args.targetNode.handle,
targetNodeCategory: args.targetNode.category,
targetNodeArcheType: args.targetNode.archetype,
} satisfies ConnectorObject;
}
55 changes: 13 additions & 42 deletions app/(playground)/p/[agentId]/beta-proto/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
MousePositionProvider,
useMousePosition,
} from "./contexts/mouse-position";
import type { FeatureFlags } from "./feature-flags/types";
import {
giselleNodeArchetypes,
promptBlueprint,
Expand All @@ -26,73 +25,46 @@ import {
GiselleNode,
GiselleNodeInformationPanel,
} from "./giselle-node/components";
import { type GiselleNodeId, panelTabs } from "./giselle-node/types";
import {
addNodesAndConnect,
selectNode,
selectNodeAndSetPanelTab,
} from "./graph/actions";
import { addNodesAndConnect } from "./graph/actions";
import { useGraph } from "./graph/context";
import type { Graph } from "./graph/types";
import { Header } from "./header";
import {
type ReactFlowNode,
edgeTypes,
nodeTypes,
} from "./react-flow-adapter/giselle-node";
import { edgeTypes, nodeTypes } from "./react-flow-adapter/giselle-node";
import {
useConnectionHandler,
useGraphToReactFlowEffect,
useKeyUpHandler,
useNodeEventHandler,
useReacrFlowEdgeEventHandler,
useReactFlowNodeEventHandler,
} from "./react-flow-adapter/graph";
import type { ReactFlowEdge, ReactFlowNode } from "./react-flow-adapter/types";
import { setSelectTool } from "./tool/actions";
import { Toolbar } from "./tool/components";
import { useTool } from "./tool/context";
import { ToolProvider } from "./tool/provider";
import type { AgentId } from "./types";

function EditorInner() {
const [previewMode, setPreviewMode] = useState(false);
const { state: toolState, dispatch: toolDispatch } = useTool();
const { dispatch: graphDispatch } = useGraph();
const { state: graphState, dispatch: graphDispatch } = useGraph();
const reactFlowInstance = useReactFlow();
const mousePosition = useMousePosition();
useGraphToReactFlowEffect();
const { handleConnect } = useConnectionHandler();
const { handleNodeDragStop } = useNodeEventHandler();
const { handleKeyUp } = useKeyUpHandler();
const { handleNodesChange } = useReactFlowNodeEventHandler();
const { handleEdgesChange } = useReacrFlowEdgeEventHandler();
return (
<div className="w-full h-screen">
<ReactFlow<ReactFlowNode>
defaultNodes={[]}
defaultEdges={[]}
<ReactFlow<ReactFlowNode, ReactFlowEdge>
nodes={graphState.graph.xyFlow.nodes}
edges={graphState.graph.xyFlow.edges}
nodeTypes={nodeTypes}
edgeTypes={edgeTypes}
panOnScroll
onKeyUp={handleKeyUp}
selectionOnDrag
panOnDrag={false}
colorMode="dark"
onConnect={handleConnect}
onNodeDragStop={handleNodeDragStop}
onNodeClick={(_, node) => {
graphDispatch(
selectNodeAndSetPanelTab({
selectNode: {
id: node.id as GiselleNodeId,
panelTab: panelTabs.property,
},
}),
);
}}
onNodesChange={handleNodesChange}
onEdgesChange={handleEdgesChange}
onPaneClick={(event) => {
event.preventDefault();
graphDispatch(
selectNode({
selectedNodeIds: [],
}),
);
if (toolState.activeTool.type === "addGiselleNode") {
const position = reactFlowInstance.flowToScreenPosition({
x: event.clientX,
Expand Down Expand Up @@ -149,7 +121,6 @@ function EditorInner() {
toolDispatch(setSelectTool);
}
}}
deleteKeyCode={null}
>
<Background
className="!bg-black-100"
Expand Down
Loading

0 comments on commit 9cb97f6

Please sign in to comment.