feat:新增dify1.11.1版本
This commit is contained in:
25
dify_1.11.1/sdks/README.md
Normal file
25
dify_1.11.1/sdks/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
# SDK
|
||||
|
||||
## Java
|
||||
|
||||
https://github.com/langgenius/java-client/
|
||||
|
||||
## Go
|
||||
|
||||
https://github.com/langgenius/dify-sdk-go
|
||||
|
||||
## Ruby
|
||||
|
||||
https://github.com/langgenius/ruby-sdk
|
||||
|
||||
## Python
|
||||
|
||||
TODO move to another place
|
||||
|
||||
## PHP
|
||||
|
||||
TODO move to another place
|
||||
|
||||
## Node.js
|
||||
|
||||
TODO move to another place
|
||||
48
dify_1.11.1/sdks/nodejs-client/.gitignore
vendored
Normal file
48
dify_1.11.1/sdks/nodejs-client/.gitignore
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# local env files
|
||||
.env*.local
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
# npm
|
||||
package-lock.json
|
||||
|
||||
# yarn
|
||||
.pnp.cjs
|
||||
.pnp.loader.mjs
|
||||
.yarn/
|
||||
.yarnrc.yml
|
||||
|
||||
# pmpm
|
||||
pnpm-lock.yaml
|
||||
67
dify_1.11.1/sdks/nodejs-client/README.md
Normal file
67
dify_1.11.1/sdks/nodejs-client/README.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Dify Node.js SDK
|
||||
|
||||
This is the Node.js SDK for the Dify API, which allows you to easily integrate Dify into your Node.js applications.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
npm install dify-client
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
After installing the SDK, you can use it in your project like this:
|
||||
|
||||
```js
|
||||
import { DifyClient, ChatClient, CompletionClient } from 'dify-client'
|
||||
|
||||
const API_KEY = 'your-api-key-here'
|
||||
const user = `random-user-id`
|
||||
const query = 'Please tell me a short story in 10 words or less.'
|
||||
const remote_url_files = [{
|
||||
type: 'image',
|
||||
transfer_method: 'remote_url',
|
||||
url: 'your_url_address'
|
||||
}]
|
||||
|
||||
// Create a completion client
|
||||
const completionClient = new CompletionClient(API_KEY)
|
||||
// Create a completion message
|
||||
completionClient.createCompletionMessage({'query': query}, user)
|
||||
// Create a completion message with vision model
|
||||
completionClient.createCompletionMessage({'query': 'Describe the picture.'}, user, false, remote_url_files)
|
||||
|
||||
// Create a chat client
|
||||
const chatClient = new ChatClient(API_KEY)
|
||||
// Create a chat message in stream mode
|
||||
const response = await chatClient.createChatMessage({}, query, user, true, null)
|
||||
const stream = response.data;
|
||||
stream.on('data', data => {
|
||||
console.log(data);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
console.log('stream done');
|
||||
});
|
||||
// Create a chat message with vision model
|
||||
chatClient.createChatMessage({}, 'Describe the picture.', user, false, null, remote_url_files)
|
||||
// Fetch conversations
|
||||
chatClient.getConversations(user)
|
||||
// Fetch conversation messages
|
||||
chatClient.getConversationMessages(conversationId, user)
|
||||
// Rename conversation
|
||||
chatClient.renameConversation(conversationId, name, user)
|
||||
|
||||
|
||||
const client = new DifyClient(API_KEY)
|
||||
// Fetch application parameters
|
||||
client.getApplicationParameters(user)
|
||||
// Provide feedback for a message
|
||||
client.messageFeedback(messageId, rating, user)
|
||||
|
||||
```
|
||||
|
||||
Replace 'your-api-key-here' with your actual Dify API key.Replace 'your-app-id-here' with your actual Dify APP ID.
|
||||
|
||||
## License
|
||||
|
||||
This SDK is released under the MIT License.
|
||||
12
dify_1.11.1/sdks/nodejs-client/babel.config.cjs
Normal file
12
dify_1.11.1/sdks/nodejs-client/babel.config.cjs
Normal file
@@ -0,0 +1,12 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
targets: {
|
||||
node: "current",
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
107
dify_1.11.1/sdks/nodejs-client/index.d.ts
vendored
Normal file
107
dify_1.11.1/sdks/nodejs-client/index.d.ts
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
// Types.d.ts
|
||||
export const BASE_URL: string;
|
||||
|
||||
export type RequestMethods = 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
||||
|
||||
interface Params {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface HeaderParams {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
interface User {
|
||||
}
|
||||
|
||||
interface DifyFileBase {
|
||||
type: "image"
|
||||
}
|
||||
|
||||
export interface DifyRemoteFile extends DifyFileBase {
|
||||
transfer_method: "remote_url"
|
||||
url: string
|
||||
}
|
||||
|
||||
export interface DifyLocalFile extends DifyFileBase {
|
||||
transfer_method: "local_file"
|
||||
upload_file_id: string
|
||||
}
|
||||
|
||||
export type DifyFile = DifyRemoteFile | DifyLocalFile;
|
||||
|
||||
export declare class DifyClient {
|
||||
constructor(apiKey: string, baseUrl?: string);
|
||||
|
||||
updateApiKey(apiKey: string): void;
|
||||
|
||||
sendRequest(
|
||||
method: RequestMethods,
|
||||
endpoint: string,
|
||||
data?: any,
|
||||
params?: Params,
|
||||
stream?: boolean,
|
||||
headerParams?: HeaderParams
|
||||
): Promise<any>;
|
||||
|
||||
messageFeedback(message_id: string, rating: number, user: User): Promise<any>;
|
||||
|
||||
getApplicationParameters(user: User): Promise<any>;
|
||||
|
||||
fileUpload(data: FormData): Promise<any>;
|
||||
|
||||
textToAudio(text: string ,user: string, streaming?: boolean): Promise<any>;
|
||||
|
||||
getMeta(user: User): Promise<any>;
|
||||
}
|
||||
|
||||
export declare class CompletionClient extends DifyClient {
|
||||
createCompletionMessage(
|
||||
inputs: any,
|
||||
user: User,
|
||||
stream?: boolean,
|
||||
files?: DifyFile[] | null
|
||||
): Promise<any>;
|
||||
}
|
||||
|
||||
export declare class ChatClient extends DifyClient {
|
||||
createChatMessage(
|
||||
inputs: any,
|
||||
query: string,
|
||||
user: User,
|
||||
stream?: boolean,
|
||||
conversation_id?: string | null,
|
||||
files?: DifyFile[] | null
|
||||
): Promise<any>;
|
||||
|
||||
getSuggested(message_id: string, user: User): Promise<any>;
|
||||
|
||||
stopMessage(task_id: string, user: User) : Promise<any>;
|
||||
|
||||
|
||||
getConversations(
|
||||
user: User,
|
||||
first_id?: string | null,
|
||||
limit?: number | null,
|
||||
pinned?: boolean | null
|
||||
): Promise<any>;
|
||||
|
||||
getConversationMessages(
|
||||
user: User,
|
||||
conversation_id?: string,
|
||||
first_id?: string | null,
|
||||
limit?: number | null
|
||||
): Promise<any>;
|
||||
|
||||
renameConversation(conversation_id: string, name: string, user: User,auto_generate:boolean): Promise<any>;
|
||||
|
||||
deleteConversation(conversation_id: string, user: User): Promise<any>;
|
||||
|
||||
audioToText(data: FormData): Promise<any>;
|
||||
}
|
||||
|
||||
export declare class WorkflowClient extends DifyClient {
|
||||
run(inputs: any, user: User, stream?: boolean,): Promise<any>;
|
||||
|
||||
stop(task_id: string, user: User): Promise<any>;
|
||||
}
|
||||
351
dify_1.11.1/sdks/nodejs-client/index.js
Normal file
351
dify_1.11.1/sdks/nodejs-client/index.js
Normal file
@@ -0,0 +1,351 @@
|
||||
import axios from "axios";
|
||||
export const BASE_URL = "https://api.dify.ai/v1";
|
||||
|
||||
export const routes = {
|
||||
// app's
|
||||
feedback: {
|
||||
method: "POST",
|
||||
url: (message_id) => `/messages/${message_id}/feedbacks`,
|
||||
},
|
||||
application: {
|
||||
method: "GET",
|
||||
url: () => `/parameters`,
|
||||
},
|
||||
fileUpload: {
|
||||
method: "POST",
|
||||
url: () => `/files/upload`,
|
||||
},
|
||||
textToAudio: {
|
||||
method: "POST",
|
||||
url: () => `/text-to-audio`,
|
||||
},
|
||||
getMeta: {
|
||||
method: "GET",
|
||||
url: () => `/meta`,
|
||||
},
|
||||
|
||||
// completion's
|
||||
createCompletionMessage: {
|
||||
method: "POST",
|
||||
url: () => `/completion-messages`,
|
||||
},
|
||||
|
||||
// chat's
|
||||
createChatMessage: {
|
||||
method: "POST",
|
||||
url: () => `/chat-messages`,
|
||||
},
|
||||
getSuggested:{
|
||||
method: "GET",
|
||||
url: (message_id) => `/messages/${message_id}/suggested`,
|
||||
},
|
||||
stopChatMessage: {
|
||||
method: "POST",
|
||||
url: (task_id) => `/chat-messages/${task_id}/stop`,
|
||||
},
|
||||
getConversations: {
|
||||
method: "GET",
|
||||
url: () => `/conversations`,
|
||||
},
|
||||
getConversationMessages: {
|
||||
method: "GET",
|
||||
url: () => `/messages`,
|
||||
},
|
||||
renameConversation: {
|
||||
method: "POST",
|
||||
url: (conversation_id) => `/conversations/${conversation_id}/name`,
|
||||
},
|
||||
deleteConversation: {
|
||||
method: "DELETE",
|
||||
url: (conversation_id) => `/conversations/${conversation_id}`,
|
||||
},
|
||||
audioToText: {
|
||||
method: "POST",
|
||||
url: () => `/audio-to-text`,
|
||||
},
|
||||
|
||||
// workflow‘s
|
||||
runWorkflow: {
|
||||
method: "POST",
|
||||
url: () => `/workflows/run`,
|
||||
},
|
||||
stopWorkflow: {
|
||||
method: "POST",
|
||||
url: (task_id) => `/workflows/tasks/${task_id}/stop`,
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export class DifyClient {
|
||||
constructor(apiKey, baseUrl = BASE_URL) {
|
||||
this.apiKey = apiKey;
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
updateApiKey(apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
async sendRequest(
|
||||
method,
|
||||
endpoint,
|
||||
data = null,
|
||||
params = null,
|
||||
stream = false,
|
||||
headerParams = {}
|
||||
) {
|
||||
const isFormData =
|
||||
(typeof FormData !== "undefined" && data instanceof FormData) ||
|
||||
(data && data.constructor && data.constructor.name === "FormData");
|
||||
const headers = {
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
...(isFormData ? {} : { "Content-Type": "application/json" }),
|
||||
...headerParams,
|
||||
};
|
||||
|
||||
const url = `${this.baseUrl}${endpoint}`;
|
||||
let response;
|
||||
if (stream) {
|
||||
response = await axios({
|
||||
method,
|
||||
url,
|
||||
data,
|
||||
params,
|
||||
headers,
|
||||
responseType: "stream",
|
||||
});
|
||||
} else {
|
||||
response = await axios({
|
||||
method,
|
||||
url,
|
||||
...(method !== "GET" && { data }),
|
||||
params,
|
||||
headers,
|
||||
responseType: "json",
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
messageFeedback(message_id, rating, user) {
|
||||
const data = {
|
||||
rating,
|
||||
user,
|
||||
};
|
||||
return this.sendRequest(
|
||||
routes.feedback.method,
|
||||
routes.feedback.url(message_id),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
getApplicationParameters(user) {
|
||||
const params = { user };
|
||||
return this.sendRequest(
|
||||
routes.application.method,
|
||||
routes.application.url(),
|
||||
null,
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
fileUpload(data) {
|
||||
return this.sendRequest(
|
||||
routes.fileUpload.method,
|
||||
routes.fileUpload.url(),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
textToAudio(text, user, streaming = false) {
|
||||
const data = {
|
||||
text,
|
||||
user,
|
||||
streaming
|
||||
};
|
||||
return this.sendRequest(
|
||||
routes.textToAudio.method,
|
||||
routes.textToAudio.url(),
|
||||
data,
|
||||
null,
|
||||
streaming
|
||||
);
|
||||
}
|
||||
|
||||
getMeta(user) {
|
||||
const params = { user };
|
||||
return this.sendRequest(
|
||||
routes.getMeta.method,
|
||||
routes.getMeta.url(),
|
||||
null,
|
||||
params
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class CompletionClient extends DifyClient {
|
||||
createCompletionMessage(inputs, user, stream = false, files = null) {
|
||||
const data = {
|
||||
inputs,
|
||||
user,
|
||||
response_mode: stream ? "streaming" : "blocking",
|
||||
files,
|
||||
};
|
||||
return this.sendRequest(
|
||||
routes.createCompletionMessage.method,
|
||||
routes.createCompletionMessage.url(),
|
||||
data,
|
||||
null,
|
||||
stream
|
||||
);
|
||||
}
|
||||
|
||||
runWorkflow(inputs, user, stream = false, files = null) {
|
||||
const data = {
|
||||
inputs,
|
||||
user,
|
||||
response_mode: stream ? "streaming" : "blocking",
|
||||
};
|
||||
return this.sendRequest(
|
||||
routes.runWorkflow.method,
|
||||
routes.runWorkflow.url(),
|
||||
data,
|
||||
null,
|
||||
stream
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class ChatClient extends DifyClient {
|
||||
createChatMessage(
|
||||
inputs,
|
||||
query,
|
||||
user,
|
||||
stream = false,
|
||||
conversation_id = null,
|
||||
files = null
|
||||
) {
|
||||
const data = {
|
||||
inputs,
|
||||
query,
|
||||
user,
|
||||
response_mode: stream ? "streaming" : "blocking",
|
||||
files,
|
||||
};
|
||||
if (conversation_id) data.conversation_id = conversation_id;
|
||||
|
||||
return this.sendRequest(
|
||||
routes.createChatMessage.method,
|
||||
routes.createChatMessage.url(),
|
||||
data,
|
||||
null,
|
||||
stream
|
||||
);
|
||||
}
|
||||
|
||||
getSuggested(message_id, user) {
|
||||
const data = { user };
|
||||
return this.sendRequest(
|
||||
routes.getSuggested.method,
|
||||
routes.getSuggested.url(message_id),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
stopMessage(task_id, user) {
|
||||
const data = { user };
|
||||
return this.sendRequest(
|
||||
routes.stopChatMessage.method,
|
||||
routes.stopChatMessage.url(task_id),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
getConversations(user, first_id = null, limit = null, pinned = null) {
|
||||
const params = { user, first_id: first_id, limit, pinned };
|
||||
return this.sendRequest(
|
||||
routes.getConversations.method,
|
||||
routes.getConversations.url(),
|
||||
null,
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
getConversationMessages(
|
||||
user,
|
||||
conversation_id = "",
|
||||
first_id = null,
|
||||
limit = null
|
||||
) {
|
||||
const params = { user };
|
||||
|
||||
if (conversation_id) params.conversation_id = conversation_id;
|
||||
|
||||
if (first_id) params.first_id = first_id;
|
||||
|
||||
if (limit) params.limit = limit;
|
||||
|
||||
return this.sendRequest(
|
||||
routes.getConversationMessages.method,
|
||||
routes.getConversationMessages.url(),
|
||||
null,
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
renameConversation(conversation_id, name, user, auto_generate) {
|
||||
const data = { name, user, auto_generate };
|
||||
return this.sendRequest(
|
||||
routes.renameConversation.method,
|
||||
routes.renameConversation.url(conversation_id),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
deleteConversation(conversation_id, user) {
|
||||
const data = { user };
|
||||
return this.sendRequest(
|
||||
routes.deleteConversation.method,
|
||||
routes.deleteConversation.url(conversation_id),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
audioToText(data) {
|
||||
return this.sendRequest(
|
||||
routes.audioToText.method,
|
||||
routes.audioToText.url(),
|
||||
data
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class WorkflowClient extends DifyClient {
|
||||
run(inputs,user,stream) {
|
||||
const data = {
|
||||
inputs,
|
||||
response_mode: stream ? "streaming" : "blocking",
|
||||
user
|
||||
};
|
||||
|
||||
return this.sendRequest(
|
||||
routes.runWorkflow.method,
|
||||
routes.runWorkflow.url(),
|
||||
data,
|
||||
null,
|
||||
stream
|
||||
);
|
||||
}
|
||||
|
||||
stop(task_id, user) {
|
||||
const data = { user };
|
||||
return this.sendRequest(
|
||||
routes.stopWorkflow.method,
|
||||
routes.stopWorkflow.url(task_id),
|
||||
data
|
||||
);
|
||||
}
|
||||
}
|
||||
141
dify_1.11.1/sdks/nodejs-client/index.test.js
Normal file
141
dify_1.11.1/sdks/nodejs-client/index.test.js
Normal file
@@ -0,0 +1,141 @@
|
||||
import { DifyClient, WorkflowClient, BASE_URL, routes } from ".";
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
afterEach(() => {
|
||||
jest.resetAllMocks()
|
||||
})
|
||||
|
||||
describe('Client', () => {
|
||||
let difyClient
|
||||
beforeEach(() => {
|
||||
difyClient = new DifyClient('test')
|
||||
})
|
||||
|
||||
test('should create a client', () => {
|
||||
expect(difyClient).toBeDefined();
|
||||
})
|
||||
// test updateApiKey
|
||||
test('should update the api key', () => {
|
||||
difyClient.updateApiKey('test2');
|
||||
expect(difyClient.apiKey).toBe('test2');
|
||||
})
|
||||
});
|
||||
|
||||
describe('Send Requests', () => {
|
||||
let difyClient
|
||||
|
||||
beforeEach(() => {
|
||||
difyClient = new DifyClient('test')
|
||||
})
|
||||
|
||||
it('should make a successful request to the application parameter', async () => {
|
||||
const method = 'GET'
|
||||
const endpoint = routes.application.url()
|
||||
const expectedResponse = { data: 'response' }
|
||||
axios.mockResolvedValue(expectedResponse)
|
||||
|
||||
await difyClient.sendRequest(method, endpoint)
|
||||
|
||||
expect(axios).toHaveBeenCalledWith({
|
||||
method,
|
||||
url: `${BASE_URL}${endpoint}`,
|
||||
params: null,
|
||||
headers: {
|
||||
Authorization: `Bearer ${difyClient.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
responseType: 'json',
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
it('should handle errors from the API', async () => {
|
||||
const method = 'GET'
|
||||
const endpoint = '/test-endpoint'
|
||||
const errorMessage = 'Request failed with status code 404'
|
||||
axios.mockRejectedValue(new Error(errorMessage))
|
||||
|
||||
await expect(difyClient.sendRequest(method, endpoint)).rejects.toThrow(
|
||||
errorMessage
|
||||
)
|
||||
})
|
||||
|
||||
it('uses the getMeta route configuration', async () => {
|
||||
axios.mockResolvedValue({ data: 'ok' })
|
||||
await difyClient.getMeta('end-user')
|
||||
|
||||
expect(axios).toHaveBeenCalledWith({
|
||||
method: routes.getMeta.method,
|
||||
url: `${BASE_URL}${routes.getMeta.url()}`,
|
||||
params: { user: 'end-user' },
|
||||
headers: {
|
||||
Authorization: `Bearer ${difyClient.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
responseType: 'json',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('File uploads', () => {
|
||||
let difyClient
|
||||
const OriginalFormData = global.FormData
|
||||
|
||||
beforeAll(() => {
|
||||
global.FormData = class FormDataMock {}
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
global.FormData = OriginalFormData
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
difyClient = new DifyClient('test')
|
||||
})
|
||||
|
||||
it('does not override multipart boundary headers for FormData', async () => {
|
||||
const form = new FormData()
|
||||
axios.mockResolvedValue({ data: 'ok' })
|
||||
|
||||
await difyClient.fileUpload(form)
|
||||
|
||||
expect(axios).toHaveBeenCalledWith({
|
||||
method: routes.fileUpload.method,
|
||||
url: `${BASE_URL}${routes.fileUpload.url()}`,
|
||||
data: form,
|
||||
params: null,
|
||||
headers: {
|
||||
Authorization: `Bearer ${difyClient.apiKey}`,
|
||||
},
|
||||
responseType: 'json',
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Workflow client', () => {
|
||||
let workflowClient
|
||||
|
||||
beforeEach(() => {
|
||||
workflowClient = new WorkflowClient('test')
|
||||
})
|
||||
|
||||
it('uses tasks stop path for workflow stop', async () => {
|
||||
axios.mockResolvedValue({ data: 'stopped' })
|
||||
await workflowClient.stop('task-1', 'end-user')
|
||||
|
||||
expect(axios).toHaveBeenCalledWith({
|
||||
method: routes.stopWorkflow.method,
|
||||
url: `${BASE_URL}${routes.stopWorkflow.url('task-1')}`,
|
||||
data: { user: 'end-user' },
|
||||
params: null,
|
||||
headers: {
|
||||
Authorization: `Bearer ${workflowClient.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
responseType: 'json',
|
||||
})
|
||||
})
|
||||
})
|
||||
6
dify_1.11.1/sdks/nodejs-client/jest.config.cjs
Normal file
6
dify_1.11.1/sdks/nodejs-client/jest.config.cjs
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
testEnvironment: "node",
|
||||
transform: {
|
||||
"^.+\\.[tj]sx?$": "babel-jest",
|
||||
},
|
||||
};
|
||||
30
dify_1.11.1/sdks/nodejs-client/package.json
Normal file
30
dify_1.11.1/sdks/nodejs-client/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "dify-client",
|
||||
"version": "2.3.2",
|
||||
"description": "This is the Node.js SDK for the Dify.AI API, which allows you to easily integrate Dify.AI into your Node.js applications.",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"types":"index.d.ts",
|
||||
"keywords": [
|
||||
"Dify",
|
||||
"Dify.AI",
|
||||
"LLM"
|
||||
],
|
||||
"author": "Joel",
|
||||
"contributors": [
|
||||
"<crazywoola> <<427733928@qq.com>> (https://github.com/crazywoola)"
|
||||
],
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.3.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.21.8",
|
||||
"@babel/preset-env": "^7.21.5",
|
||||
"babel-jest": "^29.5.0",
|
||||
"jest": "^29.5.0"
|
||||
}
|
||||
}
|
||||
1
dify_1.11.1/sdks/php-client/.gitignore
vendored
Normal file
1
dify_1.11.1/sdks/php-client/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/vendor
|
||||
95
dify_1.11.1/sdks/php-client/README.md
Normal file
95
dify_1.11.1/sdks/php-client/README.md
Normal file
@@ -0,0 +1,95 @@
|
||||
# Dify PHP SDK
|
||||
|
||||
This is the PHP SDK for the Dify API, which allows you to easily integrate Dify into your PHP applications.
|
||||
|
||||
## Requirements
|
||||
|
||||
- PHP 7.2 or later
|
||||
- Guzzle HTTP client library
|
||||
|
||||
## Usage
|
||||
|
||||
If you want to try the example, you can run `composer install` in this directory.
|
||||
|
||||
In exist project, copy the `dify-client.php` to you project, and merge the following to your `composer.json` file, then run `composer install && composer dump-autoload` to install. Guzzle does not require 7.9, other versions have not been tested, but you can try.
|
||||
|
||||
```json
|
||||
{
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^7.9"
|
||||
},
|
||||
"autoload": {
|
||||
"files": ["path/to/dify-client.php"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
After installing the SDK, you can use it in your project like this:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
$apiKey = 'your-api-key-here';
|
||||
|
||||
$difyClient = new DifyClient($apiKey);
|
||||
|
||||
// Create a completion client
|
||||
$completionClient = new CompletionClient($apiKey);
|
||||
$response = $completionClient->create_completion_message(array("query" => "Who are you?"), "blocking", "user_id");
|
||||
|
||||
// Create a chat client
|
||||
$chatClient = new ChatClient($apiKey);
|
||||
$response = $chatClient->create_chat_message(array(), "Who are you?", "user_id", "blocking", $conversation_id);
|
||||
|
||||
$fileForVision = [
|
||||
[
|
||||
"type" => "image",
|
||||
"transfer_method" => "remote_url",
|
||||
"url" => "your_image_url"
|
||||
]
|
||||
];
|
||||
|
||||
// $fileForVision = [
|
||||
// [
|
||||
// "type" => "image",
|
||||
// "transfer_method" => "local_file",
|
||||
// "url" => "your_file_id"
|
||||
// ]
|
||||
// ];
|
||||
|
||||
// Create a completion client with vision model like gpt-4-vision
|
||||
$response = $completionClient->create_completion_message(array("query" => "Describe this image."), "blocking", "user_id", $fileForVision);
|
||||
|
||||
// Create a chat client with vision model like gpt-4-vision
|
||||
$response = $chatClient->create_chat_message(array(), "Describe this image.", "user_id", "blocking", $conversation_id, $fileForVision);
|
||||
|
||||
// File Upload
|
||||
$fileForUpload = [
|
||||
[
|
||||
'tmp_name' => '/path/to/file/filename.jpg',
|
||||
'name' => 'filename.jpg'
|
||||
]
|
||||
];
|
||||
$response = $difyClient->file_upload("user_id", $fileForUpload);
|
||||
$result = json_decode($response->getBody(), true);
|
||||
echo 'upload_file_id: ' . $result['id'];
|
||||
|
||||
// Fetch application parameters
|
||||
$response = $difyClient->get_application_parameters("user_id");
|
||||
|
||||
// Provide feedback for a message
|
||||
$response = $difyClient->message_feedback($message_id, $rating, "user_id");
|
||||
|
||||
// Other available methods:
|
||||
// - get_conversation_messages()
|
||||
// - get_conversations()
|
||||
// - rename_conversation()
|
||||
```
|
||||
|
||||
Replace 'your-api-key-here' with your actual Dify API key.
|
||||
|
||||
## License
|
||||
|
||||
This SDK is released under the MIT License.
|
||||
9
dify_1.11.1/sdks/php-client/composer.json
Normal file
9
dify_1.11.1/sdks/php-client/composer.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"guzzlehttp/guzzle": "^7.9"
|
||||
},
|
||||
"autoload": {
|
||||
"files": ["dify-client.php"]
|
||||
}
|
||||
}
|
||||
663
dify_1.11.1/sdks/php-client/composer.lock
generated
Normal file
663
dify_1.11.1/sdks/php-client/composer.lock
generated
Normal file
@@ -0,0 +1,663 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "7827c548fdcc7e87cb0ae341dd2c6b1b",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
"version": "7.9.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/guzzle.git",
|
||||
"reference": "d281ed313b989f213357e3be1a179f02196ac99b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b",
|
||||
"reference": "d281ed313b989f213357e3be1a179f02196ac99b",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"guzzlehttp/promises": "^1.5.3 || ^2.0.3",
|
||||
"guzzlehttp/psr7": "^2.7.0",
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"psr/http-client": "^1.0",
|
||||
"symfony/deprecation-contracts": "^2.2 || ^3.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-client-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"ext-curl": "*",
|
||||
"guzzle/client-integration-tests": "3.0.2",
|
||||
"php-http/message-factory": "^1.1",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20",
|
||||
"psr/log": "^1.1 || ^2.0 || ^3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-curl": "Required for CURL handler support",
|
||||
"ext-intl": "Required for Internationalized Domain Name (IDN) support",
|
||||
"psr/log": "Required for using the Log middleware"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/functions_include.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Jeremy Lindblom",
|
||||
"email": "jeremeamia@gmail.com",
|
||||
"homepage": "https://github.com/jeremeamia"
|
||||
},
|
||||
{
|
||||
"name": "George Mponos",
|
||||
"email": "gmponos@gmail.com",
|
||||
"homepage": "https://github.com/gmponos"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com",
|
||||
"homepage": "https://github.com/Nyholm"
|
||||
},
|
||||
{
|
||||
"name": "Márk Sági-Kazár",
|
||||
"email": "mark.sagikazar@gmail.com",
|
||||
"homepage": "https://github.com/sagikazarmark"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"email": "webmaster@tubo-world.de",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle is a PHP HTTP client library",
|
||||
"keywords": [
|
||||
"client",
|
||||
"curl",
|
||||
"framework",
|
||||
"http",
|
||||
"http client",
|
||||
"psr-18",
|
||||
"psr-7",
|
||||
"rest",
|
||||
"web service"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/guzzle/issues",
|
||||
"source": "https://github.com/guzzle/guzzle/tree/7.9.2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Nyholm",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-07-24T11:22:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/promises",
|
||||
"version": "2.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/promises.git",
|
||||
"reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/promises/zipball/7c69f28996b0a6920945dd20b3857e499d9ca96c",
|
||||
"reference": "7c69f28996b0a6920945dd20b3857e499d9ca96c",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Promise\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com",
|
||||
"homepage": "https://github.com/Nyholm"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"email": "webmaster@tubo-world.de",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
}
|
||||
],
|
||||
"description": "Guzzle promises library",
|
||||
"keywords": [
|
||||
"promise"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/promises/issues",
|
||||
"source": "https://github.com/guzzle/promises/tree/2.2.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Nyholm",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-03-27T13:27:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
"version": "2.7.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/guzzle/psr7.git",
|
||||
"reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/guzzle/psr7/zipball/c2270caaabe631b3b44c85f99e5a04bbb8060d16",
|
||||
"reference": "c2270caaabe631b3b44c85f99e5a04bbb8060d16",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2.5 || ^8.0",
|
||||
"psr/http-factory": "^1.0",
|
||||
"psr/http-message": "^1.1 || ^2.0",
|
||||
"ralouphie/getallheaders": "^3.0"
|
||||
},
|
||||
"provide": {
|
||||
"psr/http-factory-implementation": "1.0",
|
||||
"psr/http-message-implementation": "1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"bamarni/composer-bin-plugin": "^1.8.2",
|
||||
"http-interop/http-factory-tests": "0.9.0",
|
||||
"phpunit/phpunit": "^8.5.39 || ^9.6.20"
|
||||
},
|
||||
"suggest": {
|
||||
"laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"bamarni-bin": {
|
||||
"bin-links": true,
|
||||
"forward-command": false
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GuzzleHttp\\Psr7\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Graham Campbell",
|
||||
"email": "hello@gjcampbell.co.uk",
|
||||
"homepage": "https://github.com/GrahamCampbell"
|
||||
},
|
||||
{
|
||||
"name": "Michael Dowling",
|
||||
"email": "mtdowling@gmail.com",
|
||||
"homepage": "https://github.com/mtdowling"
|
||||
},
|
||||
{
|
||||
"name": "George Mponos",
|
||||
"email": "gmponos@gmail.com",
|
||||
"homepage": "https://github.com/gmponos"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Nyholm",
|
||||
"email": "tobias.nyholm@gmail.com",
|
||||
"homepage": "https://github.com/Nyholm"
|
||||
},
|
||||
{
|
||||
"name": "Márk Sági-Kazár",
|
||||
"email": "mark.sagikazar@gmail.com",
|
||||
"homepage": "https://github.com/sagikazarmark"
|
||||
},
|
||||
{
|
||||
"name": "Tobias Schultze",
|
||||
"email": "webmaster@tubo-world.de",
|
||||
"homepage": "https://github.com/Tobion"
|
||||
},
|
||||
{
|
||||
"name": "Márk Sági-Kazár",
|
||||
"email": "mark.sagikazar@gmail.com",
|
||||
"homepage": "https://sagikazarmark.hu"
|
||||
}
|
||||
],
|
||||
"description": "PSR-7 message implementation that also provides common utility methods",
|
||||
"keywords": [
|
||||
"http",
|
||||
"message",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response",
|
||||
"stream",
|
||||
"uri",
|
||||
"url"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/guzzle/psr7/issues",
|
||||
"source": "https://github.com/guzzle/psr7/tree/2.7.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/GrahamCampbell",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/Nyholm",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2025-03-27T12:30:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
"version": "1.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-client.git",
|
||||
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90",
|
||||
"reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0 || ^8.0",
|
||||
"psr/http-message": "^1.0 || ^2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Client\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP clients",
|
||||
"homepage": "https://github.com/php-fig/http-client",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-client",
|
||||
"psr",
|
||||
"psr-18"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-client"
|
||||
},
|
||||
"time": "2023-09-23T14:17:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-factory",
|
||||
"version": "1.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-factory.git",
|
||||
"reference": "e616d01114759c4c489f93b099585439f795fe35"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35",
|
||||
"reference": "e616d01114759c4c489f93b099585439f795fe35",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0.0",
|
||||
"psr/http-message": "^1.0 || ^2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interfaces for PSR-7 HTTP message factories",
|
||||
"keywords": [
|
||||
"factory",
|
||||
"http",
|
||||
"message",
|
||||
"psr",
|
||||
"psr-17",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-factory/tree/1.0.2"
|
||||
},
|
||||
"time": "2023-04-10T20:10:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
"version": "2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-message.git",
|
||||
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
|
||||
"reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.2 || ^8.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Message\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "https://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for HTTP messages",
|
||||
"homepage": "https://github.com/php-fig/http-message",
|
||||
"keywords": [
|
||||
"http",
|
||||
"http-message",
|
||||
"psr",
|
||||
"psr-7",
|
||||
"request",
|
||||
"response"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/http-message/tree/2.0"
|
||||
},
|
||||
"time": "2023-04-04T09:54:51+00:00"
|
||||
},
|
||||
{
|
||||
"name": "ralouphie/getallheaders",
|
||||
"version": "3.0.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ralouphie/getallheaders.git",
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
|
||||
"reference": "120b605dfeb996808c31b6477290a714d356e822",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"phpunit/phpunit": "^5 || ^6.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/getallheaders.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Ralph Khattar",
|
||||
"email": "ralph.khattar@gmail.com"
|
||||
}
|
||||
],
|
||||
"description": "A polyfill for getallheaders.",
|
||||
"support": {
|
||||
"issues": "https://github.com/ralouphie/getallheaders/issues",
|
||||
"source": "https://github.com/ralouphie/getallheaders/tree/develop"
|
||||
},
|
||||
"time": "2019-03-08T08:55:37+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
"version": "v3.5.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/deprecation-contracts.git",
|
||||
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
|
||||
"reference": "74c71c939a79f7d5bf3c1ce9f5ea37ba0114c6f6",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
"function.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "A generic function and convention to trigger deprecation notices",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://symfony.com/sponsor",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://github.com/fabpot",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-09-25T14:20:29+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
206
dify_1.11.1/sdks/php-client/dify-client.php
Normal file
206
dify_1.11.1/sdks/php-client/dify-client.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class DifyClient {
|
||||
protected $api_key;
|
||||
protected $base_url;
|
||||
protected $client;
|
||||
|
||||
public function __construct($api_key, $base_url = null) {
|
||||
$this->api_key = $api_key;
|
||||
$this->base_url = $base_url ?? 'https://api.dify.ai/v1/';
|
||||
$this->client = new Client([
|
||||
'base_uri' => $this->base_url,
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $this->api_key,
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function send_request($method, $endpoint, $data = null, $params = null, $stream = false) {
|
||||
$options = [
|
||||
'json' => $data,
|
||||
'query' => $params,
|
||||
'stream' => $stream,
|
||||
];
|
||||
|
||||
$response = $this->client->request($method, $endpoint, $options);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function message_feedback($message_id, $rating, $user) {
|
||||
$data = [
|
||||
'rating' => $rating,
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('POST', "messages/{$message_id}/feedbacks", $data);
|
||||
}
|
||||
|
||||
public function get_application_parameters($user) {
|
||||
$params = ['user' => $user];
|
||||
return $this->send_request('GET', 'parameters', null, $params);
|
||||
}
|
||||
|
||||
public function file_upload($user, $files) {
|
||||
$data = ['user' => $user];
|
||||
$options = [
|
||||
'multipart' => $this->prepareMultipart($data, $files)
|
||||
];
|
||||
|
||||
return $this->client->request('POST', 'files/upload', $options);
|
||||
}
|
||||
|
||||
protected function prepareMultipart($data, $files) {
|
||||
$multipart = [];
|
||||
foreach ($data as $key => $value) {
|
||||
$multipart[] = [
|
||||
'name' => $key,
|
||||
'contents' => $value
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
$multipart[] = [
|
||||
'name' => 'file',
|
||||
'contents' => fopen($file['tmp_name'], 'r'),
|
||||
'filename' => $file['name']
|
||||
];
|
||||
}
|
||||
|
||||
return $multipart;
|
||||
}
|
||||
|
||||
|
||||
public function text_to_audio($text, $user, $streaming = false) {
|
||||
$data = [
|
||||
'text' => $text,
|
||||
'user' => $user,
|
||||
'streaming' => $streaming
|
||||
];
|
||||
|
||||
return $this->send_request('POST', 'text-to-audio', $data);
|
||||
}
|
||||
|
||||
public function get_meta($user) {
|
||||
$params = [
|
||||
'user' => $user
|
||||
];
|
||||
|
||||
return $this->send_request('GET', 'meta',null, $params);
|
||||
}
|
||||
}
|
||||
|
||||
class CompletionClient extends DifyClient {
|
||||
public function create_completion_message($inputs, $response_mode, $user, $files = null) {
|
||||
$data = [
|
||||
'inputs' => $inputs,
|
||||
'response_mode' => $response_mode,
|
||||
'user' => $user,
|
||||
'files' => $files,
|
||||
];
|
||||
return $this->send_request('POST', 'completion-messages', $data, null, $response_mode === 'streaming');
|
||||
}
|
||||
}
|
||||
|
||||
class ChatClient extends DifyClient {
|
||||
public function create_chat_message($inputs, $query, $user, $response_mode = 'blocking', $conversation_id = null, $files = null) {
|
||||
$data = [
|
||||
'inputs' => $inputs,
|
||||
'query' => $query,
|
||||
'user' => $user,
|
||||
'response_mode' => $response_mode,
|
||||
'files' => $files,
|
||||
];
|
||||
if ($conversation_id) {
|
||||
$data['conversation_id'] = $conversation_id;
|
||||
}
|
||||
|
||||
return $this->send_request('POST', 'chat-messages', $data, null, $response_mode === 'streaming');
|
||||
}
|
||||
|
||||
public function get_suggestions($message_id, $user) {
|
||||
$params = [
|
||||
'user' => $user
|
||||
];
|
||||
return $this->send_request('GET', "messages/{$message_id}/suggested", null, $params);
|
||||
}
|
||||
|
||||
public function stop_message($task_id, $user) {
|
||||
$data = ['user' => $user];
|
||||
return $this->send_request('POST', "chat-messages/{$task_id}/stop", $data);
|
||||
}
|
||||
|
||||
public function get_conversations($user, $first_id = null, $limit = null, $pinned = null) {
|
||||
$params = [
|
||||
'user' => $user,
|
||||
'first_id' => $first_id,
|
||||
'limit' => $limit,
|
||||
'pinned'=> $pinned,
|
||||
];
|
||||
return $this->send_request('GET', 'conversations', null, $params);
|
||||
}
|
||||
|
||||
public function get_conversation_messages($user, $conversation_id = null, $first_id = null, $limit = null) {
|
||||
$params = ['user' => $user];
|
||||
|
||||
if ($conversation_id) {
|
||||
$params['conversation_id'] = $conversation_id;
|
||||
}
|
||||
if ($first_id) {
|
||||
$params['first_id'] = $first_id;
|
||||
}
|
||||
if ($limit) {
|
||||
$params['limit'] = $limit;
|
||||
}
|
||||
|
||||
return $this->send_request('GET', 'messages', null, $params);
|
||||
}
|
||||
|
||||
public function rename_conversation($conversation_id, $name,$auto_generate, $user) {
|
||||
$data = [
|
||||
'name' => $name,
|
||||
'user' => $user,
|
||||
'auto_generate' => $auto_generate
|
||||
];
|
||||
return $this->send_request('PATCH', "conversations/{$conversation_id}", $data);
|
||||
}
|
||||
|
||||
public function delete_conversation($conversation_id, $user) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('DELETE', "conversations/{$conversation_id}", $data);
|
||||
}
|
||||
|
||||
public function audio_to_text($audio_file, $user) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
$options = [
|
||||
'multipart' => $this->prepareMultipart($data, $audio_file)
|
||||
];
|
||||
return $this->client->request('POST', 'audio-to-text', $options);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WorkflowClient extends DifyClient{
|
||||
public function run($inputs, $response_mode, $user) {
|
||||
$data = [
|
||||
'inputs' => $inputs,
|
||||
'response_mode' => $response_mode,
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('POST', 'workflows/run', $data);
|
||||
}
|
||||
|
||||
public function stop($task_id, $user) {
|
||||
$data = [
|
||||
'user' => $user,
|
||||
];
|
||||
return $this->send_request('POST', "workflows/tasks/{$task_id}/stop",$data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user