Skip to content

Commit

Permalink
Merge branch 'main' into dw/hashdev
Browse files Browse the repository at this point in the history
  • Loading branch information
vilkinsons authored Mar 24, 2024
2 parents 334f665 + b52d9b0 commit e31419e
Show file tree
Hide file tree
Showing 153 changed files with 1,734 additions and 670 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8
uses: github/codeql-action/init@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -47,7 +47,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8
uses: github/codeql-action/autobuild@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -61,4 +61,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8
uses: github/codeql-action/analyze@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: "Checkout Repository"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: "Dependency Review"
uses: actions/dependency-review-action@0fa40c3c10055986a88de3baa0d6ec17c5a894b3 # v4.2.3
uses: actions/dependency-review-action@733dd5d4a5203f238c33806593ec0f5fc5343d8c # v4.2.4
2 changes: 1 addition & 1 deletion .github/workflows/hash-backend-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ jobs:
if: ${{ failure() }}
steps:
- name: Slack Notification
uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907
uses: rtCamp/action-slack-notify@72c987ec9674843e8a882c6beb4fb043c1ea926e
env:
SLACK_LINK_NAMES: true
SLACK_MESSAGE: "Error deploying the HASH backend <@U0143NL4GMP> <@U027NPY8Y3X> <@U02NLJY0FGX>"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ jobs:
mv "$tmp" clippy.sarif
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
if: always() && steps.lints.outputs.has-clippy == 'true'
with:
sarif_file: ${{ matrix.directory }}/clippy.sarif
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Notify Slack on failure
uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907
uses: rtCamp/action-slack-notify@72c987ec9674843e8a882c6beb4fb043c1ea926e
if: ${{ failure() }}
env:
SLACK_LINK_NAMES: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
files: "semgrep.sarif"

- name: Upload SARIF file for GitHub Advanced Security Dashboard
uses: github/codeql-action/upload-sarif@05963f47d870e2cb19a537396c1f668a348c7d8f # v3.24.8
uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9
if: steps.sarif_file_check.outputs.files_exists == 'true'
with:
sarif_file: semgrep.sarif
2 changes: 1 addition & 1 deletion .github/workflows/tf-apply-hash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
env: ${{ matrix.env }}

- name: Notify Slack on failure
uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907
uses: rtCamp/action-slack-notify@72c987ec9674843e8a882c6beb4fb043c1ea926e
if: ${{ failure() }}
env:
SLACK_LINK_NAMES: true
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type-system.path = "libs/@blockprotocol/type-system/rust"
error-stack = { version = "0.4.1", default-features = false }

# Shared third-party dependencies
bytes = "1.5.0"
bytes = "1.6.0"
clap = { version = "4.5.3", default-features = false, features = ["std"] }
email_address = { version = "0.2.4", default-features = false }
futures = { version = "0.3.30", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions apps/hash-ai-worker-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"description": "A TypeScript 'AI' worker for HASH",
"license": "AGPL-3.0",
"type": "module",
"exports": {
".": "./src/main.ts",
"./workflows": "./src/workflows.ts",
Expand Down
8 changes: 8 additions & 0 deletions apps/hash-ai-worker-ts/scripts/bundle-workflow-code.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { writeFile } from "node:fs/promises";
import { createRequire } from "node:module";
import * as path from "node:path";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { bundleWorkflowCode } from "@temporalio/worker";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const require = createRequire(import.meta.url);

async function bundle() {
const { code } = await bundleWorkflowCode({
workflowsPath: require.resolve("../src/workflows"),
Expand Down
6 changes: 5 additions & 1 deletion apps/hash-ai-worker-ts/src/activities/infer-entities/log.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import fs from "node:fs";
import path from "node:path";
import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { Context } from "@temporalio/activity";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export const log = (message: string) => {
const requestId = Context.current().info.workflowExecution.workflowId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,17 @@ export const createEntities = async ({
proposedEntity,
operation: "create",
status: "failure",
failureReason: `Link entities must have both a sourceEntityId and a targetEntityId.${originalProposal ? `You originally proposed that entityId ${proposedEntity.entityId} should have sourceEntityId ${originalProposal.sourceEntityId?.toString() ?? ""} and targetEntityId ${originalProposal.targetEntityId?.toString() ?? ""}.` : ""}`,
failureReason: `Link entities must have both a sourceEntityId and a targetEntityId.${
originalProposal
? `You originally proposed that entityId ${
proposedEntity.entityId
} should have sourceEntityId ${
originalProposal.sourceEntityId?.toString() ?? ""
} and targetEntityId ${
originalProposal.targetEntityId?.toString() ?? ""
}.`
: ""
}`,
};
return;
}
Expand Down
6 changes: 5 additions & 1 deletion apps/hash-ai-worker-ts/src/activities/shared/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ const createPropertyEmbeddingInput = (params: {
propertyTypeSchema: Pick<PropertyType, "title">;
propertyValue: EntityPropertyValue;
}): string => {
return `${params.propertyTypeSchema.title}: ${typeof params.propertyValue === "string" ? params.propertyValue : JSON.stringify(params.propertyValue)}`;
return `${params.propertyTypeSchema.title}: ${
typeof params.propertyValue === "string"
? params.propertyValue
: JSON.stringify(params.propertyValue)
}`;
};

/**
Expand Down
8 changes: 8 additions & 0 deletions apps/hash-ai-worker-ts/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as http from "node:http";
import { createRequire } from "node:module";
import * as path from "node:path";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";

import { createGraphClient } from "@local/hash-backend-utils/create-graph-client";
import { getRequiredEnv } from "@local/hash-backend-utils/environment";
Expand All @@ -9,6 +12,11 @@ import { config } from "dotenv-flow";

import { createAiActivities, createGraphActivities } from "./activities";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const require = createRequire(import.meta.url);

export const monorepoRootDir = path.resolve(__dirname, "../../..");

config({ silent: true, path: monorepoRootDir });
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions apps/hash-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"description": "API and data store for HASH",
"license": "AGPL-3.0",
"type": "module",
"scripts": {
"build:docker": "docker buildx build --tag hash-api --file ../../infra/docker/api/prod/Dockerfile ../../ --load",
"codegen": "rimraf './src/**/*.gen.*'; graphql-codegen --config codegen.config.ts",
Expand All @@ -24,7 +25,7 @@
"@aws-sdk/credential-provider-node": "3.436.0",
"@aws-sdk/s3-presigned-post": "3.436.0",
"@aws-sdk/s3-request-presigner": "3.436.0",
"@blockprotocol/core": "0.1.2",
"@blockprotocol/core": "0.1.3",
"@blockprotocol/type-system": "0.1.1",
"@graphql-tools/schema": "8.5.0",
"@linear/sdk": "6.0.0",
Expand Down Expand Up @@ -52,6 +53,7 @@
"@sentry/node": "7.93.0",
"@snowplow/node-tracker": "3.3.1",
"@temporalio/client": "1.8.1",
"@temporalio/proto": "1.8.1",
"@types/ws": "8.5.10",
"agentkeepalive": "4.2.1",
"apollo-datasource": "3.3.2",
Expand Down Expand Up @@ -96,7 +98,7 @@
"ws": "8.15.1"
},
"devDependencies": {
"@blockprotocol/graph": "0.3.4-canary-20240313191438",
"@blockprotocol/graph": "0.3.4",
"@graphql-codegen/cli": "5.0.0",
"@graphql-codegen/introspection": "2.2.3",
"@graphql-codegen/typescript": "2.8.7",
Expand Down
12 changes: 12 additions & 0 deletions apps/hash-api/src/ai/gpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

This folder contains functions which support the use of HASH as an external datastore for a custom GPT called HashGPT.

## GPT Instructions

These instructions are set in the ChatGPT interface. They are repeated here to allow them to be version controlled.

Update them if you find that amending the GPT's instructions improves its performance.

> HashGPT is designed to give users a way of exploring the contents of the HASH knowledge graph through natural language queries. It helps users understand the contents of entities in their 'web' (an area of the HASH graph that belongs to them), or webs of the organizations they belong to. It can suggest follow-up questions that the user might like to ask about any data, based on interesting characteristics within it. HashGPT presents its findings in an informative and user-friendly manner, which may include formatted tables, graphs, and other visual aids to enhance understanding – it uses the code interpreter for these visual aids wherever possible, rather than generating images.
>
> The GPT ensures clarity and depth in responses. It never invents entities which were not included in the API response. The user values accuracy above all else – the GPT is careful to review the data thoroughly before providing an answer which takes full account of all relevant information. The GPT also biases heavily towards only using the facts in the data it gets from the HASH graph to offer answers, avoiding speculation about things not confirmed by the data unless absolutely necessary or unless the user requests it. Again, the most important thing for users is accuracy – they depend on data in the graph being represented accurately, including which entities link to which other entities. Literal, accurate and comprehensive use of data in the graph is key! Links and entities are never invented or misrepresented by HashGPT.
>
> Whenever HashGPT mentions an entity, it includes a link for the user to view more about the entity, as provided by the HASH API as entityHref.
## Development

### Fresh local instance setup
Expand Down
49 changes: 48 additions & 1 deletion apps/hash-api/src/ai/gpt/generate-hashgpt-schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { writeFileSync } from "node:fs";
import { resolve } from "node:path";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";

import { apiOrigin } from "@local/hash-isomorphic-utils/environment";
import * as generator from "ts-json-schema-generator";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const config = {
diagnostics: false,
noTopRef: true,
Expand All @@ -22,6 +26,22 @@ const {
.createGenerator(config)
.createSchema("GptQueryEntitiesResponseBody");

const { $ref: queryTypesRequestRef, definitions: queryTypesRequestDefs } =
generator
.createGenerator({
...config,
path: resolve(__dirname, "gpt-query-types.ts"),
})
.createSchema("GptQueryTypesRequestBody");

const { $ref: queryTypesResponseRef, definitions: queryTypesResponseDefs } =
generator
.createGenerator({
...config,
path: resolve(__dirname, "gpt-query-types.ts"),
})
.createSchema("GptQueryTypesResponseBody");

const { $ref: getUserWebsResponseRef, definitions: getUserWebsResponseDefs } =
generator
.createGenerator({
Expand All @@ -34,6 +54,8 @@ const components = {
schemas: {
...queryEntitiesRequestDefs,
...queryEntitiesResponseDefs,
...queryTypesRequestDefs,
...queryTypesResponseDefs,
...getUserWebsResponseDefs,
},
};
Expand Down Expand Up @@ -97,6 +119,31 @@ const openApiSchema = {
},
},
},
"/gpt/entities/query-types": {
post: {
description:
"Retrieve entity types which match a semantic query, or which belong to a specific web",
operationId: "queryTypes",
"x-openai-isConsequential:": false,
requestBody: {
content: {
"application/json": {
schema: { $ref: queryTypesRequestRef },
},
},
},
responses: {
"200": {
description: "response",
content: {
"application/json": {
schema: { $ref: queryTypesResponseRef },
},
},
},
},
},
},
},
components,
};
Expand Down
Loading

0 comments on commit e31419e

Please sign in to comment.